Packet在IP層的大冒險

2021-10-24 16:13:36 字數 3855 閱讀 1709

從udpl4傳下來之後

void 

ipv4l3protocol::send (ptr packet,

ipv4address source,

ipv4address destination,

uint8_t protocol,

ptr route)

uint8_t tos =0;

//讀取packettag中的tos優先順序

socketiptostag iptostag;

found = packet-

>removepackettag (iptostag);if

(found)

// handle a few cases:

// 1) packet is destined to limited broadcast address

// 2) packet is destined to a subnet-directed broadcast address

// 3) packet is not broadcast, and is passed in with a route entry

// 4) packet is not broadcast, and is passed in with a route entry but route->getgateway is not set (e.g., on-demand)

// 5) packet is not broadcast, and route is null (e.g., a raw socket call, or icmp)

//一般為3或者5

// 1) packet is destined to limited broadcast address or link-local multicast address

if(destination.isbroadcast (

)|| destination.islocalmulticast ())

for(

uint32_t index =

0; index < outinte***ce-

>getnaddresses (

); index++)}

if(sendit)

}return;}

// 2) check: packet is destined to a subnet-directed broadcast address

uint32_t ifaceindex =0;

for(ipv4inte***celist::iterator ifaceiter = m_inte***ces.begin ();

ifaceiter != m_inte***ces.end (

); ifaceiter++

, ifaceindex++)}

}// 3) packet is not broadcast, and is passed in with a route entry

// with a valid ipv4address as the gateway

if(route && route-

>getgateway (

)!= ipv4address ())

// 4) packet is not broadcast, and is passed in with a route entry but route->getgateway is not set (e.g., on-demand)

if(route && route-

>getgateway (

)== ipv4address ())

// 5) packet is not broadcast, and route is null (e.g., a raw socket call)

ns_log_logic (

"ipv4l3protocol::send case 5: passed in with no route "

<< destination)

; socket::socketerrno errno_;

ptr oif (0)

;// unused for now

ipheader = buildheader (source, destination, protocol, packet-

>getsize (

), ttl, tos, mayfragment)

; ptr newroute;

if(m_routingprotocol !=0)

else

if(newroute)

else

}

void

ipv4l3protocol::sendrealout (ptr route,

ptr packet,

ipv4header const

&ipheader)

//從route中讀取藉口(inte***ce)

ptr outdev = route-

>getoutputdevice ();

int32_t inte***ce = getinte***cefordevice (outdev)

; ns_assert (inte***ce >=0)

; ptr outinte***ce = getinte***ce (inte***ce)

; ns_log_logic (

"send via netdevice ifindex "

<< outdev-

>getifindex (

)<<

" ipv4inte***ceindex "

<< inte***ce);if

(!route-

>getgateway (

).isequal (ipv4address (

"0.0.0.0"))

)//判斷目的ip是都在本子網內,不在的話發給閘道器

}else

}else

}else

//若再本子網內,直接發給目的主機

}else

}else

}}

ipv4inte***ce::send (ptr p, const ipv4header & hdr, ipv4address dest)中,實際上就是執行一些與netdevice操作。若介面可用,就會直接把分組傳送給netdevice物件。必要時還會呼叫位址解析協議arp來獲取目標節點的mac位址。

void

ipv4inte***ce::send (ptr p,

const ipv4header & hdr, ipv4address dest)

// check for a loopback device, if it's the case we don't pass through

// traffic control layer

if(dynamiccast

(m_device))

ns_assert (m_tc !=0)

;// is this packet aimed at a local inte***ce ?

for(ipv4inte***ceaddresslistci i = m_ifaddrs.begin (

); i != m_ifaddrs.end ();

++i)}if

(m_device-

>needsarp ())

else

if(dest.ismulticast ())

else}if

(!found)}if

(found)

}else

}

之後發往tc層

龍龍的暑假貪心演算法大冒險

今年暑假不ac?是的。那你幹什麼呢?看世界盃呀,笨蛋!確實如此,世界盃來了,球迷的節日也來了,估計很多acmer也會拋開電腦,奔向電視了。作為球迷,一定想看盡量多的完整的比賽,當然,作為新時代的好青年,你一定還會看一些其它的節目,比如新聞聯播 永遠不要忘記關心國家大事 非常6 7 超級女生,以及王小...

從《驚濤大冒險》想到的團隊領導問題

驚濤大冒險 是個不錯的好萊塢電影,值得一看,看後還是有很多感慨!以乙個目前文化如此蒼白無力的國家,幻想超越美國,顯得是多麼力不從心,甚至可笑可悲?團隊領導,從軍士長蘭德爾身上也可以看到很多。其次是胸懷,能夠容忍下屬主要工作能力外的小錯誤,甚至小毛病,能夠加以引導。如果蘭德爾沒有這樣的胸懷,不是通過去...

從《驚濤大冒險》想到的團隊領導問題

驚濤大冒險 是個不錯的好萊塢電影,值得一看,看後還是有很多感慨!以乙個目前文化如此蒼白無力的國家,幻想超越美國,顯得是多麼力不從心,甚至可笑可悲?團隊領導,從軍士長蘭德爾身上也可以看到很多。其次是胸懷,能夠容忍下屬主要工作能力外的小錯誤,甚至小毛病,能夠加以引導。如果蘭德爾沒有這樣的胸懷,不是通過去...