CSCI1600: Embedded and Real Time Software

Slides:



Advertisements
Similar presentations
Umut Girit  One of the core members of the Internet Protocol Suite, the set of network protocols used for the Internet. With UDP, computer.
Advertisements

CCNA – Network Fundamentals
Intermediate TCP/IP TCP Operation.
Guide to TCP/IP, Third Edition
Chapter 7 Intro to Routing & Switching.  Upon completion of this chapter, you should be able to:  Explain the need for the transport layer.  Identify.
Network Services Networking for Home & Small Business.
Chapter 7 Protocol Software On A Conventional Processor.
© 2007 Cisco Systems, Inc. All rights reserved.Cisco Public 1 Version 4.0 OSI Transport Layer Network Fundamentals – Chapter 4.
ECE 526 – Network Processing Systems Design Software-based Protocol Processing Chapter 7: D. E. Comer.
EEC-484/584 Computer Networks Lecture 13 Wenbing Zhao
WXES2106 Network Technology Semester /2005 Chapter 8 Intermediate TCP CCNA2: Module 10.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Gursharan Singh Tatla Transport Layer 16-May
1 Semester 2 Module 10 Intermediate TCP/IP Yuda college of business James Chen
Interrupts and DMA CSCI The Role of the Operating System in Performing I/O Two main jobs of a computer are: –Processing –Performing I/O manage and.
LWIP TCP/IP Stack 김백규.
Network Services Networking for Home & Small Business.
TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong.
1 The Internet and Networked Multimedia. 2 Layering  Internet protocols are designed to work in layers, with each layer building on the facilities provided.
Networking Basics CCNA 1 Chapter 11.
Lecture 4 Overview. Ethernet Data Link Layer protocol Ethernet (IEEE 802.3) is widely used Supported by a variety of physical layer implementations Multi-access.
Network Protocols and Standards (Part 2). The OSI Model In 1984, the International Organization for Standardization (ISO) defined a standard, or set of.
CSCI1600: Embedded and Real Time Software Lecture 25: Real Time Scheduling III Steven Reiss, Fall 2015.
CSCI1600: Embedded and Real Time Software Lecture 22: Networking, IPC Steven Reiss, Fall 2015.
CSCI1600: Embedded and Real Time Software Lecture 9: Input Output Concepts Steven Reiss, Fall 2015.
Lecture 4 Mechanisms & Kernel for NOSs. Mechanisms for Network Operating Systems  Network operating systems provide three basic mechanisms that support.
CSCI1600: Embedded and Real Time Software Lecture 16: Advanced Programming with I/O Steven Reiss, Fall 2015.
UDP: User Datagram Protocol Chapter 12. Introduction Multiple application programs can execute simultaneously on a given computer and can send and receive.
© 2002, Cisco Systems, Inc. All rights reserved..
TCP/IP1 Address Resolution Protocol Internet uses IP address to recognize a computer. But IP address needs to be translated to physical address (NIC).
Networking Using the OSI Model.
The Transport Layer Implementation Services Functions Protocols
Chapter 9: Transport Layer
Fast Retransmit For sliding windows flow control we waited for a timer to expire before beginning retransmission of a packet TCP uses an additional mechanism.
Module 12: I/O Systems I/O hardware Application I/O Interface
Instructor Materials Chapter 9: Transport Layer
LWIP TCP/IP Stack 김백규.
5. End-to-end protocols (part 1)
Layered Architectures
06- Transport Layer Transport Layer.
Overview Parallel Processing Pipelining
1 Input-Output Organization Computer Organization Computer Architectures Lab Peripheral Devices Input-Output Interface Asynchronous Data Transfer Modes.
Networking for Home and Small Businesses – Chapter 6
Networking for Home and Small Businesses – Chapter 6
Net 431 D: ADVANCED COMPUTER NETWORKS
Transport Layer Unit 5.
Transport Layer Our goals:
CSCI 315 Operating Systems Design
Asynchronous Serial Communications
UNIX Sockets Outline Homework #1 posted by end of day
Multimedia and Networks
Process-to-Process Delivery:
CS4470 Computer Networking Protocols
I/O Systems I/O Hardware Application I/O Interface
Operating Systems Chapter 5: Input/Output Management
Operating System Concepts
13: I/O Systems I/O hardwared Application I/O Interface
TCP/IP Protocol Suite: Review
CPEG514 Advanced Computer Networkst
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Networking for Home and Small Businesses – Chapter 6
CSCI1600: Embedded and Real Time Software
COMP3221: Microprocessors and Embedded Systems
Process-to-Process Delivery: UDP, TCP
Computer Networks Protocols
Chapter 13: I/O Systems.
Transport Layer 9/22/2019.
Exceptions and networking
Module 12: I/O Systems I/O hardwared Application I/O Interface
Chapter 13: I/O Systems “The two main jobs of a computer are I/O and [CPU] processing. In many cases, the main job is I/O, and the [CPU] processing is.
Presentation transcript:

CSCI1600: Embedded and Real Time Software Lecture 23: Networking, IPC Steven Reiss, Fall 2017

Interprocess Communication Multiple tasks need to communicate We’ve covered shared memory Using synchronization where necessary When is synchronization necessary? What other means are there? Can we combine communication and synchronization? And have the underlying system ensure it is correct Lecture 25: Networking 11/7/2018

Semaphores We saw semaphores as a synchronization mechanism Protect a synchronized region Protect a set of resources Protect a producer-consumer queue They can also be used for communication When the amount of information is small Flag to let another task run Only need semaphore, no shared variable Lecture 25: Networking 11/7/2018

Are Semaphores Sufficient? Semaphores are low level and error-prone Getting communications and synchronization right Can be tricky Can lead to hard to find and replicate problems Only a small amount of information passed Or you need to do synchronization Higher level abstractions can be easier to use And can be supported by a RT operating system What abstractions are appropriate? How do you send messages to others? Lecture 25: Networking 11/7/2018

Mailboxes What it is Operations Messages A synchronized holder for a single message Operations create – initialize a mailbox structure accept – takes in a message if there pend – waits for a message post – sends a message Messages void * (arbitrary pointer) Lecture 25: Networking 11/7/2018

Mailbox Implementation Mutex for operations Queue of waiting tasks Create: set up everything, empty mailbox Accept: check if mailbox is empty, if not, empty it Pend: Wait until the mailbox is non-empty Put task on wait queue for mailbox Then get message and return it Conflicts can be FIFO, priority-based, random Lecture 25: Networking 11/7/2018

Mailbox Implementation Post: If queued tasks, find proper waiter and remove from queue Insert message into mailbox Let that task continue Else if there already is a message, return error Else save message and return Note that all operations are synchronized appropriately What mailboxes can’t do Multiple messages (but can prioritize) Blocking on post Lecture 25: Networking 11/7/2018

Message Queues Similar to mailboxes Differences More than one message at a time Can be dynamic or fixed maximum sized Messages are void* again Block on send At least optionally Lecture 25: Networking 11/7/2018

Message Queue Implementation What does this look like Synchronized producer consumer queue Handling multiple readers and writers What this doesn’t handle Variable sized messages Communication without shared memory Lecture 25: Networking 11/7/2018

Pipes Similar to message queues except Handle varying sized messages May be entirely byte oriented May take <length,data> for messages Can work across processes if messages lack pointers Can work across machines But have to be wary of endian problems Lecture 25: Networking 11/7/2018

Higher Level Abstractions Imply higher level bugs Bugs are less likely to be synchronization related Data-oriented problems to watch out for Using the wrong queue/pipe/mailbox Misinterpreting the passed data “Ownership” of passed pointers Wanting to ignore duplicate messages Lecture 25: Networking 11/7/2018

Wider Scale Communications Might want to do more Communicate between processes Communicate between devices (e.g. in a car) Means for doing so Attached devices: point-to-point communication Busses Ethernet: MAC (Media Access Control), UDP Ethernet: TCP, IP Lecture 25: Networking 11/7/2018

Commonalities Framing: putting messages together Error detection Flow control Reliability and guarantees Bus “arbitrarion” / MAC protocols Lecture 25: Networking 11/7/2018

Internetworking Embedded web server interface IP cameras, switches, … Post information to a server Sensors, … Data from network shares Music player, web radio Act as browsable share (TiVo) Home automation, VoIP, alarms Lecture 25: Networking 11/7/2018

Internetworking UDP (covered in CSCI1680) TCP/IP Not very different from interacting with a bus Best effort delivery (no reliability guarantees, acks) You manage retries, assembly/disassembly, congestion, acks Good for sensor updates, etc. TCP/IP Similar to a IPC pipe Adds reliability, byte stream interface Internally manages retries, ordering, etc. Web services, simple APIs Lecture 25: Networking 11/7/2018

TCP/IP Sockets are like 2-way pipes Sockets are address by host-port Both sides can read/write independently Sockets are address by host-port Connection to a socket Create socket on the server Bind it to a known port (on the known host) Do an accept on the socket Create a socket on the client Connect to know server socket (connect) operation Server does accept on its socket This yields a new socket bound to that client Lecture 25: Networking 11/7/2018

TCP/IP Lightweight implementation exist (even for Arduino) Library interface for lwIP (Light Weight IP) ip_input(pbuf,netif) Takes an IP packet and the network interface as args Does TCP/IP processing for the packet tcp_tmr() Should be called every 100ms Does all TCP timer-base processing such as retransmission Event-based callbacks This is not sockets, but it is TCP/IP Lecture 25: Networking 11/7/2018

lwIP Basics Initialization: tcp_init Manage all TCP connections tcp_tmr() Must be called every 250 milliseconds sys_check_timeout() Calls tcp_tmr and other network related timers Lecture 25: Networking 11/7/2018

lwIP Server Connection tcp_new : create a PCB for a new socket tcp_bind : bind that socket to a port on this host tcp_listen : listen for connections tcp_accept : specify a callback to call Passed routine called when someone tries to connect tcp_accepted : called from the routine to accept the connection Lecture 25: Networking 11/7/2018

lwIP Client Connection tcp_new : create new PCB (socket) tcp_bind : bind the socket to target host/port tcp_connect : establish the connection Provides callback function Called when connected Or if there is an error in the connection Lecture 25: Networking 11/7/2018

lwIP Sending Data tcp_sent : specify callback function Called when data acknowledged by remote host tcp_sndbuf : return maximum data that can be sent Space in the output queue tcp_write : enqueues the data for write Can be via copy or in-place tcp_output : forces data to be sent Lecture 25: Networking 11/7/2018

lwIP Receiving Data tcp_recv : specifies a callback function Function called when data is received Or when there is an error (connection closed) tcp_recved : acknowledges data Needs to be called by callback routine to indicate data read Lecture 25: Networking 11/7/2018

lwIP Other Functions tcp_poll : handle idle connections tcp_close : close a connection tcp_abort : forcibly close a connection tcp_err : register an error handling callback Lecture 25: Networking 11/7/2018

Simple Web Server Assuming the host IP is known Create a server socket on port 80 Listen for connections Read message from connection Should be header + body Simple message = header only Decode header, branch on URL Compute output page Send reply on the connection HTTP header + HTML body Lecture 25: Networking 11/7/2018

Sample Code: Minimal Server main() { struct tcp_pcb * pcb my_accept(void * arg,struct tcp_tcb_new(); tcp_pcb * pcb) { tcp_bind(pcb,NULL,80); tcp_recv(pcb,my_recv,NULL); tcp_listen(pcb); tcp_accept(pcb,my_accept,NULL); /* main loop */ my_recv(void * arg, } struct tcp_pcb *pcb,struct pbuf * p) {   // do something with packet p Lecture 25: Networking 11/7/2018

Simple Web Communicator To send periodic updates Put together a message Simple HTTP header URL using ?x=v1&y=v2 to encode data Connect to <SERVER HOST:80> Send the message Close connection Alternatives Use arbitrary message format Use arbitrary host/port for the server Send and receive messages in that format Lecture 25: Networking 11/7/2018

Homework SOUND LAB (FRIDAY) Read 12.1 – 12.2 Read lab handout, do preliminaries (FRIDAY) Read 12.1 – 12.2 Exercise 12.1 Lecture 25: Networking 11/7/2018

Point-to-Point Framing Sentinals Special bytes at beginning and end of message Escaped when inside a packet Length counts Encode length of the packets explicitly Bit errors may introduce big mistages Clock-based Each frame is t microseconds long Keep clocks synchronized with transitions Lecture 25: Networking 11/7/2018

Example: RS232 Serial Ports Many variants exist, 2 wire is simplest A byte is encoded as 0bbbbbbbb1 (10 bits per byte) bbbbbbbb is LSB first Leave TX asserted until next byte Software flow control: XON, XOFF Hardware flow control Two extra wires: RTS, CTS Lecture 25: Networking 11/7/2018

MACs and Arbitration Time based Devices work out which uses the medium Bus arbitration MAC protocols Lecture 25: Networking 11/7/2018

What is a bus System lines Address and data Arbitration Error lines Includes clock and reset Address and data 32 time mux lines for address and data Interrupt and validate lines Arbitration Not shared Controlled by PCI bus arbiter Error lines Lecture 25: Networking 11/7/2018

PCI Bus Arbitrarion Four interrupt lines, rotated per device Level triggered interrupts Hard to miss Hard to share Shared 33.33Mhz clock 32 bit width => 133MB max transfer speed Lecture 25: Networking 11/7/2018

PCI Bus Arbitration Bus master holds the right to use the bus at any time Different strategies can be used to assign the master Daisy chain (round robin) – each gets a turn Independent requests Each device has its own signal it can send to controller Polling Controller counts through all devices Device raises a flag when it wants to communicate Lecture 25: Networking 11/7/2018

Programmed I/O vs DMA CPU – MEMORY also has a bus Read/Write to memory With address lines With data lines With control lines (IRQ, NMI, VMA, R/W, BUS, RESET) Read/Write to memory Sets address lines Reads/writes using data lines BUS, R/W lines indicate when to read/write Enable lines on devices wired directly to appropriate memory Based on high order lines and low order lines Lecture 25: Networking 11/7/2018

Ethernet Framing Carrier sense multiple access with collision detection If line is idle Send immediately with fixed max frame size Wait 9.6 microseconds between back-to-back frames If line is busy Wait until idle and transmit immediately If collision occurs Jam for 32 bits, then stop transmitting Delay (random exponential backoff) and try again Lecture 25: Networking 11/7/2018

Sample Code – Main Loop for ( ; ; ) { if (poll_driver(netif) == PACKET_READY) { pbuf = get_packet(netif); ip_input(pbuf,netif); } if (clock() – last_time >= 100 * CLOCK_MS) { tcp_tmr(); last_time = clock(); Lecture 25: Networking 11/7/2018

Sample Code: Minimal Server main() { http_accept(void * arg,struct struct tcp_pcb * pcb tcp_pcb * pcb) { tcp_tcb_new(); tcp_recv(pcb,http_recv,NULL); tcp_bind(pcb,NULL,80); tcp_listen(pcb); tcp_accept(pcb,http_accept,NULL); http_recv(void * arg, /* main loop */ struct tcp_pcb *pcb,struct pbuf * p) { } // do something with packet p   Lecture 25: Networking 11/7/2018