1 / 4

Parts of example codes

This code example demonstrates the use of useful structures such as ConnectionList, TCPState, ConnectionToStateMapping, IPHeader, TCPHeader, and Connection. Includes functions for DFListen and SOCKConnect.

knowlesm
Download Presentation

Parts of example codes

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Parts of example codes Yan Gao Feb. 10, 2006

  2. Some useful structures • ConnectionList<State> “constate.h” • TCPState “tcpstate.h” • ConnectionToStateMapping<State> “constate.h” • IPHeader “ip.h” • TCPHeader “tcp.h” • Connection “sockint.h”

  3. Examples void DFListen(TCPHeader &tcph, Connection &c, Time &current_time) { unsigned char flags=0; tcph.GetFlags(flags); if(IS_SYN(flags)) { unsigned int seqnum; //Store remote side sequence number and connection info. With a new connection, tcph.GetSeqNum(seqnum); // send SYN/ACK with my sequence number Connection cnew = c; Time newto = current_time; newto.tv_sec += 5; TCPState newtcp(initSeqNum, SYN_RCVD, 8); newtcp.SetLastRecvd(seqnum); ConnectionToStateMapping<TCPState> csm(cnew, newto, newtcp, true); clist.push_front(csm); //Add new connection to list ConnectionList<TCPState>::iterator cs = clist.FindMatching(cnew); unsigned short window; tcph.GetWinSize(window); (*cs).state.SetSendRwnd(window); if(cs == clist.end()) { cerr << "Some problem finding the newly inserted tuple" << endl; } SendSynAck(cs); } }

  4. void SOCKConnect(SockRequestResponse &req) { Time current_time; if (gettimeofday(&current_time, 0) < 0) { cerr << "Can't obtain the current time.\n"; exit(-1); } ConnectionList<TCPState>::iterator cs = clist.FindMatching(req.connection); if(cs == clist.end()) { cerr << "Creating new connection." << endl; //Create a new connection with a timeout to receive Connection cnew = req.connection; // the SYN/ACK Time newto = current_time; newto.tv_sec += 5; TCPState newtcp(initSeqNum, SYN_SENT, 8); ConnectionToStateMapping<TCPState> csm(cnew, newto, newtcp, true); clist.push_front(csm); //Add new connection to list } cs = clist.FindMatching(req.connection); if(cs == clist.end()) { cerr << "Some problem finding the newly inserted tuple" << endl; } SendSyn(cs); SockRequestResponse repl; //Send back result code repl.type=STATUS; repl.connection=req.connection; repl.bytes=0; repl.error=EOK; MinetSend(sock,repl); }

More Related