 We're looking at transport protocols now. So the the second to top layer and We introduced very briefly Well, we mentioned that there are two main transport protocols TCP and UDP TCP is the They can come in for sure more than welcome TCP is Used the most in the internet today And in fact in this course we'll just focus on on TCP There are others and We introduced the concept that we now have a new type of an address a port number a Port number identifies think of applications or more specifically Connections created by individual applications so IP addresses Identified devices on the internet, but on those devices we may run many applications at the same time So we need a way to identify them and we can use port numbers for that Most internet applications we communicate between software on different computers They're structured using a client server model That is we can think of one application as the client and the other is a server where The simplest Differences between the client and the server is that the client initiates the communication Okay, so there's an application running on my computer an application on some other computer one of them initiates the communications the client in this case It sends a message to the server application What does a server do? nothing Until a client contacts it So the server just sits there normally and waits for a client to initiate the communications and Once the client contacts a server by sending it a packet the server may respond and Then they'll use some protocol to communicate and Generally, they can communicate in both directions that is client can send data to server and server can send data back to client So we often distinguish the client server based on who initiates the communications the client does An example your web browser we think of as a client And a web server a piece of software running on some other computer is the server application the server just sits there Waiting for clients to contact it so when you Open your browser and type in a URL and press enter that triggers the client application to contact the server and To exchange the data in the case of a web browser to web server to request a web page and send back that web page Now for this to work Since the client initiates the communications the client must know the address of The server that it's wanting to contact First it needs to know the IP address of the server computer So the server computer is somewhere on the internet To know which one to contact we need to know the IP address of that server computer Assuming we know it's IP address Then there's more things that we need to know and We'll introduce a new address We've mentioned it before but a new one is called a protocol number The protocol number Indicates the transport protocol being used for this data exchange So each transport protocol has a number associated with it TCP has number six always UDP 17 Others ICMP is one and there are others. Okay, I'll show you a list later Protocol numbers identify the transport protocol being used and In fact both endpoints both applications you will use the same transport protocol to exchange that data So if I choose to use TCP That it means the protocol number is six We'll see where it's sent and communicated to the other side shortly And then we've got a port number Which identifies the application on the other computer that we want to contact And we saw and that's what we introduced the the previous lecture for example Port number 80 identifies the web server application that we want to contact So in fact we have three addresses coming into play here the IP address think of that is the address of the device the Protocol number is the address of the transport protocol being used the number for the transport protocol and a port number is The address of the application on that computer that we were communicating with let's see an example and how that's That's used So here's an example two computers on the internet some source host and some destination host somewhere on the internet We'll assume that they have some IP address they both have IP addresses and Those computers are using the internet protocol at the network layer They implement different transport protocols focus on TCP and UDP, but there may be others implemented and They may be running different applications at some point in time So this actually it's a bit of an old example But on the source host is running a web browser some instant messaging client some Microsoft chat program some voice over IP application to make a voice call over the internet and The destination host is running a web server some instant messaging client and Also a voice over IP. So imagine we're chatting chatting with Sending instant messages between these two computers and at the same time making a voice call between these two computers and at the same time You have your web browser open accessing the server on that computer Three different applications being used at the same time between these two hosts Let's look at that From the perspective of sending a packet from the source host to the destination host So imagine that now we'll look at details of the IP datagram sent across the internet to this destination and I've drawn it. Okay. There's some data and If we're looking at say the web browsing data We're using TCP as the transport protocol So there's a TCP header and we're using IP as the the network layer protocol So there's an IP header and there may be other headers, but let's just focus on that this Datagram is sent from the source host across the internet to the destination host Well, how do we make sure how does the internet cloud here make sure that this datagram gets to this destination host Inside the IP header There's a source and destination address IP addresses and Just a reminder This is the IP header from one of our earlier slides The important parts initially the source IP address and destination IP address They are included in the header of the datagram Destination IP address should be the IP address of this destination host Let's give it a value just to keep it simple Let's say our source host as IP address 1.1.1.1 And the destination host is 2.2.2.2 So that the IP addresses of those computers in the internet So this IP datagram inside the IP header Those two fields The source IP address and destination IP address will be set to their respective values So inside the header i'll try and draw that Okay, we have a A source address It's coming from 1.1.1.1 And destination So how do our routers in the internet know to deliver this IP datagram to this particular host? Based upon the destination IP address And the routers will use the IP to deliver that to that specific host And so that's our normal IP forward So let's assume that this datagram gets to the destination host Now the question is The datagram arrives at the destination host because the destination address matches the IP address of this host It gets here. It's processed. It gets to IP It's delivered to the IP software in that destination host Now that IP software has this datagram Which transport protocol do we deliver that contents of that IP datagram to? So there are in this case. I've drawn three trans three potential transport protocols TCP UDP ICMP So the IP software receives this datagram and now it needs to deliver that Data to one of those three transport protocols. Which one does it deliver to and why? We don't know Let's ignore that The computer and the IP software that just received this datagram doesn't know what application the source used It's just received the datagram What could we use to identify? Okay, stop there in the header. Where? There's another field What is that field? Protocol number field So in the IP header When we created that datagram at the source We set the source IP address to 1.1.1.1 Set the destination IP address And this protocol field in here Is set to the value indicating which transport protocol is being used And if we're using TCP as the example the value is six So we'll write that as well the protocol number And it's set in the header of the IP datagram Because it's defined in some standard somewhere that says TCP is protocol number six So yes, it's set in the header of the IP datagram so that When the IP software receives this datagram Okay, it's destined to me good The protocol number is six therefore I will deliver the contents That is this portion To the TCP component of the computer So we can think that that datagram is received And delivered To IP And then IP looks at the datagram in particular looks at the protocol number in the field sees the value is six I know that six means TCP therefore deliver that contents to TCP As opposed to sending it to UDP ICMP or some other protocol So the protocol number is important here identifies the transport protocol Now TCP receives the data Or receives this portion When we haven't covered TCP yet, but we'll see the structure of that TCP header in a moment TCP receives the data does some processing And now TCP needs to decide Which application do I send it to on this computer? Do I send it to the web server or this instant messaging software? What do we use To know which application to send it to The port numbers the port numbers identify the applications And we'll come to this later. So that was the IP header the three address values, which were important other source IP destination IP and the protocol number The TCP header we'll cover in detail later, but it looks like this And note the first two fields source port destination port Inside the TCP header are those two values of The port number of the application that it came from And the port number of the application it's going to So those two fields are set which tells TCP where to send it So let's give them some values Let's say that the port number Make up some values four zero one two three And what's the port number used by web servers? 18 is the default port number by Web browsers normally it's a dynamic port it changes What's the port number used by microsoft notification protocol the microsoft messenger program Anyone know It does but it's changed over time and you I had to look it up So you don't remember these values. I looked it up and I think it's at least in the past. It was 1863 the value Again, yeah, I don't expect you to remember that but the point is that these two applications would be using different values different port numbers so In the ip datagram We contained a tcp segment and in the tcp header. There was a source port and a destination port And let's say this packet belonged to our web browsing session So the values the source port Came from our web browser 40123 with the value assigned a sign and destination port When my computer created this packet The values that set to the header field source port and destination port are the 40123 and destination web server Port number 80 So these values were set by the source computer when it created this datagram Of course, there are other values in the headers, but these are the addressing values which are important So that when computer 2.2.2 receives this datagram It looks okay destination is me. Okay. I'll take the data I need to send it to tcp because the protocol number is six and tcp corresponds to protocol number six so I deliver That data up to tcp and tcp looks at the destination port number This the data inside this tcp segment must go to the application identified by port number 80 Which is our web server? So tcp has different applications it could potentially send to the port number identifies which one And sends that up to the web server And then the web server processes the data and does what it needs to do depending upon that That data received So we're just seeing how the addressing is used now. We have really three types of addresses IP addresses That identified devices on the internet Protocol numbers that identify transport protocols And note that at both endpoints we use the same transport protocol So there's only there's no source protocol number destination protocol number. There's just one value because The source and the destination use the same transport protocol. They must So we have protocol number six meaning tcp And then we have a port number that identifies the application Or a part of that application On the particular host So the source port identifies the connection from the web browser and the destination port identified the web server in this pass It turns out your web browser can create multiple connections. So it may have multiple port numbers There's not just one port number for every web browser It's a bit more complex IP addresses protocol number port numbers The three main types of addresses that we use in the internet to identify our data communications web server receive this data All right, where did or let's go back the Source host created this packet and set these values So the source host when it wanted to send data it set these values. Okay. How did it know which values to use? We'll start with the simple ones the source host knows its own IP address So we can set the source IP address here. Okay, my computer knows its IP address is 1.1.1 one more dot one I always forget And sets the value in the source IP address in the IP header field We've assumed that the source host knows the IP address of the computer. It wants to contact Okay, and we saw That well in practice normally the end user the human user doesn't remember an IP address They remember some domain name like ict or sit so There's another protocol that will map that domain name to a destination IP address so You either know the IP address that as I remember that the IP address of My computer is or some computer is 10 dot 10 dot 100 dot 184 Or more conveniently I remember a domain name and that domain name maps to an IP address So if we know who we want to contact Then that gives us the destination IP address Different applications use different transport protocols. So my web browser application uses tcp So when my software creates this datagram, it knows it's using tcp So set the protocol number to six so that can be set those three values Where do the port numbers come from? when my web browser Starts and wants to connect to a server the operating system assigns it a port number it's usually Assigned from a range of possible port numbers for example In my case the operating system assigned my web browser port number 40123 for this connection And since it's a web browser by default it will assume that it's contacting a web server and web servers use port number 80 So therefore sets the destination port to 80 The human user of the web browser may change those values that you don't have to always contact port 80 in some cases web servers use different port numbers We'll see an example later of maybe You could use a Different specify a different port number. We'll see when we look at addressing later Now the source host creates this packet Sets these values. It's sent across the internet. It gets to the destination. It gets to the web server The web server wants to send a reply That's normal when we're communicating. We want to exchange data in both directions. We want to send a reply Where do we send the reply to? Well, we make use of the source values When the server sends a reply The destination IP address will now be the source IP address of the packet received The reply will be destined to 1.1.1.1 The source will be 2.2.2.2 So we just swap them to send the reply and same with the port numbers the web server source port 80 Sending to the web browser destination port 40123 And the protocol number will be the same six again. So for this to work The Source computer must know the port number of the server And the IP address of the server Usually the protocol number comes from the application being used. They use Defined protocols tcp or utp That's why we use common port numbers for common server applications What are known as well-known ports or even registered ports Port number 80 always for web servers Port number 443 always for secure web servers htps and others So that the client Can assume that that's the destination port number the user doesn't have to specify that The user just needs to specify the IP address Or more conveniently the domain name which is mapped to an IP address Any questions on how these addresses are used? Combining transport and network by our protocols The evaluation was done this morning Which means we can have another quiz at the end of this lecture On transport protocol addresses and maybe another quiz Next week So we'll be prepared for some quizzes in class And I can make them as hard as I like because the evaluation is done This concept of running multiple applications even multiple transport protocols inside the one host and using the addresses to identify them Is sometimes referred as multiplexing So going back to our slides I don't know if I called it Sometimes this Multiple applications multiple transport protocols multiplexing is another name So protocol numbers are defined for different transport protocols There's a standard that defines and lists them Port numbers 16 bit values up to around 65,000 are split into ranges There are what's called well-known ports which Have been around for a long time used for very common servers Zero up to 1,023 Then registered ports Which are usually also used for servers But newer ones and maybe not so common And then the remaining ports 49,152 up Are usually used by clients We call them dynamic or private ports But there may be some difference amongst the split here You can go to that website and find the list of those protocol numbers and ports On my computer I have them listed Unix computers have them in a file The file protocols lists the Protocol numbers These are just some of them ICMP1, TCP6, UDP17 and others Others that we will not talk about So 30 or 40 protocol numbers there going up to the value 142 Then there's a list of the port numbers or the well-known port Or the common port numbers for different servers or services Some of them you may recognize Some we will not, we will just browse through quickly FTP is a protocol used for transferring files Port number 21 SSH secure shell is used to log in to other computers port number 22 Email uses I don't always get these confused email uses SMTP port 25 DNS servers use port 53 Web browsers Web servers, sorry HTTP port 80 So this is the definition of which servers use which port numbers And many others many I don't know 443 is for secure Secure web servers HTTPS And there's a whole list and then we move into that what's called the registered ports Above a thousand and 23 which again are mainly for servers Different servers And that list goes on and on Some other servers if you would look in the lists MySQL database servers use 3306 Game servers if you're playing online games will use Usually registered port numbers so that you know your game client knows which game server to contact Steam uses 27,000 we're in the range of 27,000 as a port number So this is common to all transport protocols port numbers and protocol numbers Let's introduce TCP the transmission control protocol Used in most applications you use on a regular basis browsing email file sharing Date accessing databases many Applications developed inside companies use TCP applications that are transferring data files Use TCP because it provides reliability It means when you download something It's Unless it reports an error you're certain that the data you received is the same as the data that was sent IP and UDP do not provide that Some multimedia applications use it some make use of UDP There's a there's not well Defined which ones they use What does TCP do? It's what's called a stream oriented protocol The idea with TCP is we want to transfer some data from a to b That data may be coming from the application as multiple different messages The application wants to send a message to the server Then a little bit later wants to send another message From TCP's perspective those messages Have no meaning It just treats them as a stream of bytes a sequence of bytes It doesn't treat them as two different messages And we'll see that when we look at how we use sequence numbers in TCP It's a little bit different from how we've seen it in other protocols So we'll come back to see why What we mean by stream oriented TCP sets up a connection before we transfer data We the client contacts the server saying I want to transfer some data And the server will respond saying yes, let's transfer some data And during that connection setup they'll negotiate some parameters In preparation for the data transfer so we say it's connection oriented We set up a connection and then send the data When we're finished sending the data we close that connection Buffet transfer we will not try to describe now and We'll come back to it after we've gone through some of the other features Full duplex connection we set up a connection with TCP One initiates the connection to the the destination But once the connection's set up we can send data in either direction So if the client connects to the server The client can send data to the server and the server can send data back to the client It provides error control We'll see that we send data we expect axe to come back And if we don't receive axe we'll retransmit It provides flow control We'll send data, but we're not allowed to send too much such that we'll overflow the receiver So we've seen those mechanisms error control. We've seen in ARQ mechanisms Stop and wait Go back and selective reject TCP uses a variation of selective reject And we've seen flow control in stop and wait flow control and sliding window flow control and TCP uses sliding window flow control And the other one is congestion control Which is making sure the sender doesn't send too fast to overflow the routers along the path To avoid congestion in the internet We haven't seen any features of that or any examples of that yet and we will not There's some quite complex algorithms for how that works But needs another entire topic on that What we're going to focus on For TCP is look at how do we set up a connection and how do we send data And we'll come back to how that leads to stream oriented data transfer First the TCP segment. It's called a segment normally TCP packet or segment And the header Normally contains 20 bytes There's some optional header fields. We'll ignore them. They are used in some features But to keep it simple we'll ignore any options and then data So this TCP segment is put inside an IP datagram The fields of the TCP segment We've already mentioned The source application sets the source port field And the application we're sending to The port number of that application is set in the destination port For error control For retransmissions for flow control even congestion control will use sequence numbers So we'll send some data and we'll attach a sequence number to that data So when we send a TCP segment we'll include the current sequence number inside the header It's a 32 bit value Okay, so we can think we've seen it again in our protocols Frame number zero frame number one frame number two. They are the sequence numbers who use a similar concept in TCP We will send segments containing data to the destination and the destination can send back acts And those those acts include a number an acknowledgement number saying Thank you for the sequence of data I've just received the next value in the sequence. I expect is this and that value is included in that acknowledgement number We've seen this concept before where we send data with sequence number zero We send back an act saying thank you. I now expect sequence number one would say the act number is one So we include two numbers in the header. They're not always used header length If we have options the header length may vary so normally it's 20 bytes But in some cases it may be larger. So we specify how long reserved. We don't use reserve for future use Flags will come back to in a moment on one of the later slides Advertise window is used for flow control We'll not explain how it's used but it's a it's used to indicate How much the source is allowed to send so that we don't overflow the receiver There's a check sum so when the receiver receives the segment it can check are there any errors inside this segment So some error detection scheme Urgent pointer is used in special cases where we want to indicate that this data has some priority over other data And to give it some priority Options will not cover then we include the data the flags Are one bit values that indicate some feature that is enabled in this segment And there are a number of different values that can be taken They can take So that lists those header fields And let's look at the flags So a flag is a one bit value. It's either on or off If the value is bit one then we say that flag is on or up and if it's Bit zero then it's off or false So there are a range of bits In the header the flag bits and each bit has a different meaning and these How many do we have eight Are listed here those eight values are the meanings of the eight bits in the flags field We're not just explain all of them what They mean is if the value is one in that position In the header it means that feature is on If it's zero that feature is off in this segment There's an act flag What that means is that the tcp segment there's only one type of segment But we are going to have to send data and send back acts And that a way that it works in tcp is that if we're sending back an acknowledgement To tell the The receiver that this is an acknowledgement will set the act flag to be on to be true If this data or if this segment is not an act just contains data then the act flag will be off Okay, so we actually piggyback the acknowledgments onto the data The other some we will not see We'll see later a sin flag a fin maybe even a reset flag Sin meaning synchronize which means that if this flag is set This segment has some special meaning It's a segment to synchronize the sequence numbers Let's look at sequence numbers and how we set up a connection in tcp So the idea now is that we want to send data between our two devices our two hosts Using tcp. We set up a connection first The client contacts the server and says I want to send some data to you And the server will respond saying yes, you can And they'll negotiate some parameters in doing that What's the exact exchange for doing this connection setup? We'll see that with tcp And one thing that they'll negotiate is what sequence numbers to use So tcp uses 32 bit sequence numbers They're used in the error control flow control. So we need to use sequence numbers We don't always start at zero with these sequence numbers So when actually when we set up a connection We negotiate between each endpoint. What's the initial sequence number to start with? It doesn't have to be zero If you remember back to some of our slides about flow control and error control I saw I wrote frame with sequence number zero frame with sequence number one So we started at zero always in tcp for each connection We normally don't start at zero We usually started a value which is greater than what we used in a previous connection So maybe when I boot my computer up the first connection it starts at sequence number zero I transfer some data up until sequence number 100 The next connection I'll start at 101 And keep increasing So in tcp Because we don't always start at the same sequence number We need to tell the other side or negotiate with the other side which initial sequence number we want to start with so The source will choose an initial sequence number and tell the destination This is the value I want to start with And because we have a full duplex connection The destination will also choose its own sequence number initial sequence number What can we do in the last 10 minutes? Let's see how we set up a tcp connection introduce the three-way handshake so What we want to do before transferring data is set up a connection and the way that we do that in tcp The most common way is this three-way handshake Three-way meaning we are going to exchange three messages so Computer a wants to set up a connection to computer b Using tcp Well to set up a connection we exchange three messages a sends a message to b b replies And then a sends the third message the final confirmation And once we set up a connection after that we can transfer data between a and b One purpose of this Setting up a connection a three-way handshake is to negotiate or inform the other side of what initial sequence numbers we use And the way that works is that a will choose an initial sequence number some value 100 for example And send a tcp segment to b including that sequence number b if it accepts that will send back an acknowledgement saying That initial sequence number you chose is acceptable And also b will choose its own initial sequence number is and b And send that back to a and the final message is a saying yes, the sequence number b chose is okay So they agree upon initial sequence numbers from both sides Let's see that in a specific example So computer a wants to connect to b As a think of a as the client it initiates the communications to the server the first one of the first things It does is it chooses the initial sequence number it wants to use Let's choose a value isn meaning initial sequence number for a Let's say it chooses 301 What value will it choose it would depend upon what's happened in the past But let's say it chooses 301 the idea is that For the data that it sends It's going to start from 301 and an increase from there It sends a message to b saying i want to use 301 and inside that message it sets We go back to the packet header So the tcp segment It sets the sequence number field to the value of the isn it chose So the sequence number field Inside this tcp segment sn the sequence number Is set to 301 I will not draw the all the fields just the important ones for this connection setup And the other thing that it does in the header is to inform b that this tcp segment is a special tcp segment It's a segment to synchronize the sequence numbers And the way that it does that Is using one of the flags The flags There's one flag called sin you synchronize When we set this flag to one It means the sequence number is one of the initial sequence numbers we've chosen Or is the initial sequence number we chose it's saying This segment is to it to synchronize our sequence numbers So we say we set the sin flag on this segment The other flags are not important or are set to zero But this first segment sin flag is set to one And the common way that we'll draw that on the the packets is simply note This segment Is a sin segment It's a tcp segment, but the meaning is to synchronize sequence numbers B receives this segment Because the sin flag is set it realizes that this is a trying to set up a connection and Note the a chose sequence number 301 Assuming b accepts that In a normal case we accept that what b does is it sends back an act And in the response tcp segment to send back an act Say the act number Where does the act number come from? Back to our tcp header in every tcp segment. There are two numbers We can fill in the sequence number and an act number So in this response segment the act number would be set to a number to acknowledgement this initial sequence number received 302 The way that it works as we've seen with acts all the time b receives initial sequence number 301 That's okay. I'll send back an act with act number 302 saying the next value I expect is 302 and to Indicate that this tcp segment is an acknowledgement. It would set the act flag to be true Again another flag in the in the packet header. We saw there's a sin flag. There's also an act flag So we say this is an act tcp segment These are the values in the header But also at the same time it's common to do it in the same message b will inform a of its initial sequence number b chooses its own independent sequence number and that's going to be used for the data transfer from b to a Because we have a full duplex connection in we can transfer data in both directions. We'll use a different set of sequence numbers So b let's say chooses the value 46 b wants to start with 46 so in this One tcp segment it now sets the sequence number to be 46 And it sets the sin flag to be true because this segment is also About b trying to synchronize sequence numbers with a just to make it clear these values Are all part of that one segment or the header values. These two were in the first segment Not just values in the tcp segment header A receives this message and a recognizes that b accepted its initial sequence number Because the act says it's okay And also recognizes that b has chosen an initial sequence number of 46 And the final step is send back an act Acknowledging 46 So it will set the act number in the response to 47 Saying I accept 46 the next one I expect is 47 and set the act field or the act flag to be true So those fields are in the the third segment when b receives that b knows That a has accepted the initial sequence number it shows And they've set up the connection That's the the normal way for setting up a tcp connection. There's three way exchange of messages Synchronized sequence numbers they do other things when they set up the connection like allocate memory in preparation for the data transfer But they negotiate the sequence numbers Then and we'll see this next week once we start transferring data We include sequence numbers in the data What values do we start from when a sends data to b it will start with sequence number 302 And when b sends data to a it will start with sequence number 47 Because the way the acts work Initial sequence number 301 thinks that's for the first message the act number 302 says b is now expecting sequence number 302 So the first piece of data sent would contain sequence number 302 And as they send data those sequence numbers would increase This is an important part of how tcp works. We'll see it and you probably saw it in your assignment and we'll see it In a few examples this semester and especially next semester in some labs so It's Important part and it's necessary in tcp, but we'll see it has some some overhead Let's stop there. What we'll do next week to cover tcp is look now How do we transfer data in particular? How do we use the sequence numbers in the data transfer? And that will cover most of tcp and then we'll just have one more last example using htdp So that will finish the course