Parts of example codes Yan Gao Feb 10
Parts of example codes Yan Gao Feb. 10, 2006
Some useful structures o o o Connection. List<State> “constate. h” TCPState “tcpstate. h” Connection. To. State. Mapping<State> “constate. h” IPHeader “ip. h” TCPHeader “tcp. h” Connection “sockint. h”
Examples void DFListen(TCPHeader &tcph, Connection &c, Time ¤t_time) { unsigned char flags=0; tcph. Get. Flags(flags); if(IS_SYN(flags)) { unsigned int seqnum; //Store remote side sequence number and connection info. With a new connection, tcph. Get. Seq. Num(seqnum); // send SYN/ACK with my sequence number Connection cnew = c; Time newto = current_time; newto. tv_sec += 5; TCPState newtcp(init. Seq. Num, SYN_RCVD, 8); newtcp. Set. Last. Recvd(seqnum); Connection. To. State. Mapping<TCPState> csm(cnew, newto, newtcp, true); clist. push_front(csm); //Add new connection to list Connection. List<TCPState>: : iterator cs = clist. Find. Matching(cnew); unsigned short window; tcph. Get. Win. Size(window); (*cs). state. Set. Send. Rwnd(window); if(cs == clist. end()) { cerr << "Some problem finding the newly inserted tuple" << endl; } } } Send. Syn. Ack(cs);
void SOCKConnect(Sock. Request. Response &req) { Time current_time; if (gettimeofday(¤t_time, 0) < 0) { } cerr << "Can't obtain the current time. n"; exit(-1); Connection. List<TCPState>: : iterator cs = clist. Find. Matching(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(init. Seq. Num, SYN_SENT, 8); Connection. To. State. Mapping<TCPState> csm(cnew, newto, newtcp, true); clist. push_front(csm); //Add new connection to list cs = clist. Find. Matching(req. connection); if(cs == clist. end()) { cerr << "Some problem finding the newly inserted tuple" << endl; } Send. Syn(cs); } Sock. Request. Response repl; repl. type=STATUS; repl. connection=req. connection; repl. bytes=0; repl. error=EOK; Minet. Send(sock, repl); //Send back result code
- Slides: 4