Notes for September 21st

Media access in wireless networks

        stationA            stationB                stationC
-------------------------------
               -------------------------------------------------
                                    --------------------------------------------------------------------


Ethernet packet format
----------------------------------------------------------------------------------------------------------------------------------------------
| Preamble | Dest address | Src address | Frame type | data                          | CRC
----------------------------------------------------------------------------------------------------------------------------------------------
  8 bytes        6 bytes            6 bytes          2 bytes        46 - 1500 bytes         4 bytes

Preamble signals the beginning of a new packet
Frame type tells us if the packet contains arp, ip, appletalk, ipx, etc.

Types of ethernet addresses

A computer connected to the network will receive packets with destination addresses that match the unicast, broadcast, or multicast address

Promiscuous mode

Ring Topology

    Advantages of token ring
    Disadvantages
    Examples
FDDI
CDDI
FDDI on copper
    same format
    same data rate
    not immune to noise
FDDI Hub
    stations attatch to hub
    hub skips station if a station is off
    ring is inside hub box, computers attatch to box.  Called "star shaped ring"
FDDI failure recovery
    FDDI uses two rings instead of one (Dual attatched)
    Each ring goes in opposite direction
    Automatic failure recovery, aka self healing
    If there is a failed station, the neighboring stations will create a loopback using the second network
ATM
    Another example of star topology
    Asynchronous transfer mode
    designed by telephone companies
    telephone companies wanted to accomodate voice, video, and data
    the building block was an ATM switch.
    telcos wanted us to use networks in the same way we us phones..  charged by the call, by the minute, with dedicated lines between two computers.  internet tries its best, first come first serve.


Notes for September 23rd
Iterative server
    Socket -> bind(ms..) -> listen(ms..) -> while (1) { ss = accept(ms...);  process req(ss);  close(ss); }

Concurrent server configurations:
    Fork: create new process for every request
    Newthread: create a new thread to process every request
    Pool of threads: have a pre-created pool of threads to handle request

Fork:
    while(1) {
        ss = accept(ms, ...);
        if (ss < 0 && errno == EINTR) {
            continue; // sometimes signals make accept return prematurely
        }
        int ret = fork();
        if (ret == 0) {
            // This is the child process
            process request(ss);  // put call to close(ss) inside process request so we don't need to close it here
            exit(0);
        }
        if (ret < 0) {
            // error
            perror("fork");
            exit(1);
        }
        close(ss);
    }

New Thread:
    while(1) {
        ss = accept(ms...);
        ptrhreadcreate(0, processReq, (void *)ss); // set processReq close ss
    }

Thread Pool:
    void processingThread(int ms) {
        while(1) {
            pthread_mutex_lock(&mutex);
            int ss = accept(ms, ...);
            pthread_mutex_unlock(&mutex);
            processRequest(ss);
        }
    }

    int main () {
        for (int i = 0; i < maxthr; i++) {
            pthread_iterate(0, processingThread((void *)ms);
        }
        processingThread(ms);
    }

Pool of threads is faster than the other approaches since no new process is created and no new thread is created
Fork implementation is more robust.  A crash in process request will only affect the child but not the parent, the parent continues running.


Process Request (SS)
The http client sends
GET /file http/1.0 <crlf>
<client-info><crlf>
<cookies><crlf>
...
..
..
<....><crlf>
<crlf>
read the first line that contains the file requested.
keep reading until you reach <crlf><crlf> even if you do'nt need that info, otherwise connection can be closed prematurely.
file contains the document requested
when using sockets
    n = read(ss, buff, maxLength)
    n can be less than maxLength since sockets will return the bytes available so far
answer request:
    use write(ss, buff, len)
    content type: text/html <crlf>   // check website to double check doc/html.  maybe text/html
    <crlf>   // empty line seperates header from data
    document data
    close connection