1.3. IP Service Model

“IP provide deliberately simple, dumb, minimal service”

I. Network Layer:

is responsible send IP datagram to the other end: IP Datagram = IP Data + IP Header

IP(Internet Protocol) is only one protocol must used by Network Layer

II. IP Service’s Property

1. Datagram: self-contained, individual hop-by-hop routing

2. Unreliable: no promise delivered to destination, that is it is not registered mail

3. Best effort: only makes errors, certain conditions happened

4. Connectionless: communication doesn’t start by establishing connection to end

III. IP Service is simple and minimal: WHY?

1. To keep network simple:

packet delivered quickly at low cost maintenance

2. End-to-End principle:

network can become easier to evolve if complicated feature implemented at end host(software). Not in hardware of the Internet

3. Allow a reliable / unreliable choice on top layer

let application choose the reliability(i.e. TCP / UDP) for performance reasons

4. Can work over any link layer:

IP makes a very little expectation of the link layer below. So any of link layer technologies(i.e. wired, wireless) can be implemented

IV. Other services provided by IP

1. TTL(Times To Live: Hop Count): prevent packet looping forever

2. Fragment packets if they are too long to send as itself:

each link layer has maximum bandwidth to send a frame at a time

3. Use header checksum to reduce chance of wrong destination on delivery

4. Allow compatible with new version of IP: IPv6

5. Allow new fields added to datagram header:

pros: new service can be added using new fields

cons: break the goal of simple and minimal design of IP

V. IP Datagram Detail…

IPv4_DATAGRAM

1.2. The 4 Layer Internet Model

Layering is core concept to boost reusability and modularity in network design”

“Each layer doesn’t have to regard how the right below layer worked, it is Abstraction

I. Link Layer

carry the data(called frame) over one link at a time, hop-by-hop.

i.e. Ethernet(wired), Wi-Fi(wireless)

II. Network Layer

deliver data(called datagram) end-to-end, from src to des

*IP(Internet Protocol): Network Layer must use IP: not reliable, ordering, error-check

III. Transport Layer: TCP / UDP

deliver data(called packet) from src application to des application

A. TCP(Transmission Control Protocol):

1. Reliability: re-transmit until received successfully

2. In-Order: guarantee correct in-order delivery

i.e. web client, e-mail client

B. UDP(User Datagram Protocol):

no reliable, no ordering

i.e. video conferencing

IV. Application Layer:

have their-own protocol parsing semantics of byte-stream served by Transport Layer

i.e. http, ftp, www, ssh, telnet, dns, dhcp, sip

“Layer can use the service provided layer right below by well-defined API”

V. Terminology

A. Packet = data + header

header is meta-data describing what data is, where it is going, it comes from

OSI7_and_4LAYER_Mdoel
[OSI 7-layer to 4-layer Internet Model]

Computer Network

I. Course Goal: STANFORD OCW – Prof. Nick McKeown, Philip Levis

Understand protocols, design of the Internet and principles of Computer Network

II. Course Topics:

Unit 1. The Internet and IP

Unit 2. Transport

Unit 3. Packet-Switching: mathematically heavy part

Unit 4. Congestion Control

————— Midterm Exam —————-

Unit 5. Applications and NATs

Unit 6. Routing

Unit 7. Lower Layers

Unit 8. Security

—————– Final Exam —————–

IV. Text Book:

Larry L. Peterson. Computer Networks: A Systems Approach

James F. Kurose. Computer Networks: Top-Down Approach

V. Plan:

∗ Each unit might take about 8 – 10 hours of week

Chapt 8. Basic object-oriented programming

8.13 Friend functions and classes: (Learn C++)

friend function: function that can access private member of the class

friend class: if class A is friend of B, then B can access private member object A’s

∗ ‘friend’ must be declared inside of class, but in can be private or public section

∗ friend functions is not, rigorously, member of the class

∗ friend relationship is asymmetric, not symmetric

Chapt 9. Operator Overloading

9.1. Introduction to Operator Overloading (Learn C++)

A. Constraints

1. cannot overload

a. ‘? :’ – Conditional operator

b. ‘sizeof’ – sizeof operator

c. ‘::’ – scope resolution

d. ‘.’ – member selector

e. ‘.*’ – member pointer selector

2. cannot create new operator

3. cannot rename existing operator

4. at least one of operand should be user-defined type

5. cannot change number of operands

6. cannot change default ‘precedence’ and ‘associativity’

9.2. Overloading the arithmetic operators (+, -, *, /) (Learn C++)

By using keyword ‘friend’, you can overload arithmetic operator

Source Code

9.3. Overloading the I/O operators (>>, <<) (Learn C++)

Input Operator(‘<<‘)   : std::cin is type of ‘isream’

Output Operator(‘>>’): std::cout is type of ‘ostream’

Source Code

9.4. Overloading using member functions (Learn C++)

KEY: left operand is fixed – becomes implicit ‘*this’ object

Not every operator can be overloaded as member functions

i.e. ‘>>’, ‘<<‘

Not every operators can be overloaded as friend functions

i.e. ‘[]’, ‘=’, ‘->’

Source Code

9.5. Overloading unary operator (+, -, !) (Learn C++)

implement as member function, because it operator on itself

9.6. Overloading the comparison operator (<,>,==) (Learn C++)

Source Code

9.8. Overloading the subscript operator ‘[]’ (Learn C++)

A. operator[] returns a ‘l-value’ (reference)

int& operator[] (const int index) { return array[index]; }

9.10. Overloading Typecasts (Learn C++)

• No return type syntax included

Source Code

9.11. & 14. Copy constructor and Overloading assignment operator

both do same function, but called in difference cases

A. Copy Constructor (Learn C++)

parameter must passed by reference, not by value

When called

1. instantiating and initializing a new object from already existing object

2. passing an object by value

3. object is returned from a function by value

B. Assignment Operator (Learn C++)

default memberwise assignment operator provided by C++ compiler

should be member function to ease accessing private field

should check to avoid self-assignment

return ‘*this‘ so can chain the assignment operator

9.12 Shallow vs Deep copying (Learn C++)

A. Shallow Copy(=Memberwise Copying)

C++ provide default shallow copy constructor and assignment operator

B. Deep Copy

Must implement your won copy constructor and assignment overloading in case class has dynamically allocated variables

C. Prevent Copy

Place into private field, if you don’t want your class object to be copied

Chapt 11. Inheritance

11.1. Introduction to Inheritance (Learn C++)

‘Inheritance’ is one of two ways to build complex class (the other is ‘composition’)

reusability‘ is fundamental idea of inheritance

base (or parent): the object being inherited from i.e. fruit

derived (or child): the object doing inheriting i.e. apple

by default, children inherit all of properties from parent

children can redefine, hide inherited properties and add new properties

11.2. Basic inheritance in C++ (Learn C++)

derived class inherit all of member variables and functions of base class

inheritance hierarchy: must be from ‘general’ to ‘specific’

11.3. Order of construction of derived class (Learn C++)

execute constructors from base(top) to derived(leaf) following inheritance tree

∗ Order of destruction: from derived(leaf) to base(top)

Source Code

11.4. Constructors and initialization of derived class (Learn C++)

C++ allows to set specific base constructor to call before derived constructor

 Source Code

11.5. Access Specifiers (Learn C++)

A. Member Access Specifiers

1. Public: derived and outside can directly access it

3. Private: derived and outside can’t directly access it

3. Protected: only derived can access it

Source Code

B. Inheritance Access Specifiers

1. Public(mostly used): all members inherited maintain member access specifiers

2. Private(rarely used): all members inherited become private

3. Protected(not used): public members inherited become protected

Note! : It only affect outside access, not in immediate derived class

Source Code

11.6. Add, Redefine, Insert and Hide (Learn C++)

A. Add new functionality

can define new functions in derived

Source Code

B. Redefine inherited functionality : Polymorphism

can override inherited functions in derived what makes ‘polymorphism

 ∗ redefined function does not inherit the access specifier

Source Code

C. Insert inherited functionality

can insert inherited function in another function → reusability

* recommend use scope resolution operator(::) to make explicit

Source Code

D. Hide inherited functionality

can change access specifier of inherited functions directly accessible in derived

* ‘private’ can’t change to public or protected, because it is invisible in derived

Source Code

11. 7. Multiple Inheritance (Learn C++)

Conclusion: It turns out that most of problems can be handled by ‘Single Inheritance’

 Therefore, think once again before using multiple inheritance

 because, it can lead to complex, naming conflict and diamond problem

11. 8. Virtual base classes (Learn C++)

‘virtual’ keyword means base class will be created later and shared on inheritance

therefore, it is responsible for most derived to construct virtual base class

can handle the diamond problem one of issue in multiple inheritance