@@ -150,69 +150,84 @@ BridgeP4NetDevice::ReceiveFromDevice (Ptr<NetDevice> incomingPort, Ptr<const Pac
150150 Ptr<ns3::Packet> ns3Packet ((ns3::Packet *) PeekPointer (packet));
151151
152152 // check if ethernet packet
153+ // EthernetHeader eeh_1;
154+ // if (ns3Packet->PeekHeader (eeh_1))
155+ // {
156+ // NS_LOG_DEBUG ("Ethernet packet");
157+ // // log the ethernet header information
158+ // Mac48Address src_mac = eeh_1.GetSource ();
159+ // Mac48Address dst_mac = eeh_1.GetDestination ();
160+ // uint16_t protocol_eth = eeh_1.GetLengthType ();
161+ // NS_LOG_DEBUG ("* Ethernet header: Source MAC: " << src_mac << ", Destination MAC: " << dst_mac
162+ // << ", Protocol: " << protocol_eth);
163+ // }
164+
165+ // // check if ipv4 packet
166+ // Ipv4Header ip_hd;
167+ // if (ns3Packet->PeekHeader (ip_hd))
168+ // {
169+ // NS_LOG_DEBUG ("IPv4 packet");
170+ // // log the ipv4 header information
171+ // Ipv4Address src_ip = ip_hd.GetSource ();
172+ // Ipv4Address dst_ip = ip_hd.GetDestination ();
173+ // uint8_t protocol_ip = ip_hd.GetProtocol ();
174+ // uint8_t ttl_ip = ip_hd.GetTtl ();
175+ // uint16_t id_ip = ip_hd.GetIdentification ();
176+ // uint16_t len_ip = ip_hd.GetPayloadSize ();
177+ // uint16_t frag_ip = ip_hd.GetFragmentOffset ();
178+ // NS_LOG_DEBUG ("** Ipv4 header: Source IP: "
179+ // << src_ip << ", Destination IP: " << dst_ip
180+ // << ", Protocol: " << static_cast<uint32_t> (protocol_ip)
181+ // << ", TTL: " << static_cast<uint32_t> (ttl_ip) << ", ID: " << id_ip
182+ // << ", Length: " << len_ip << ", Fragment Offset: " << frag_ip);
183+ // // std::cout << "** Ipv4 header: Source IP: " << src_ip << ", Destination IP: " << dst_ip
184+ // // << ", Protocol: " << static_cast<uint32_t> (protocol_ip)
185+ // // << ", TTL: " << static_cast<uint32_t> (ttl_ip) << ", ID: " << id_ip
186+ // // << ", Length: " << len_ip << ", Fragment Offset: " << frag_ip << std::endl;
187+ // }
188+
189+ // // check if arp packet
190+ // ArpHeader arp_hd;
191+ // if (ns3Packet->PeekHeader (arp_hd))
192+ // {
193+ // NS_LOG_DEBUG ("ARP packet");
194+ // // log the arp header information
195+ // Address src_mac = arp_hd.GetSourceHardwareAddress ();
196+ // Address dst_mac = arp_hd.GetDestinationHardwareAddress ();
197+ // Ipv4Address src_ip = arp_hd.GetSourceIpv4Address ();
198+ // Ipv4Address dst_ip = arp_hd.GetDestinationIpv4Address ();
199+ // NS_LOG_DEBUG ("** Arp header: Source MAC: " << src_mac << ", Destination MAC: " << dst_mac
200+ // << ", Source IP: " << src_ip
201+ // << ", Destination IP: " << dst_ip);
202+ // // std::cout << "** Arp header: Source MAC: " << src_mac << ", Destination MAC: " << dst_mac
203+ // // << ", Source IP: " << src_ip << ", Destination IP: " << dst_ip << std::endl;
204+ // }
205+
206+ std::cout << " ns3::BridgeP4NetDevice::ReceiveFromDevice" << std::endl;
207+ ns3Packet->Print (std::cout);
208+ std::cout << " " << std::endl;
209+
210+ // Add ethernet header for the packet, this is because the csma-net-device for each port will remove the
211+ // ethernet header, so we add another ethernet header, avoid modifications to existing mods.
153212 EthernetHeader eeh_1;
154213 if (ns3Packet->PeekHeader (eeh_1))
155214 {
156215 NS_LOG_DEBUG (" Ethernet packet" );
157- // log the ethernet header information
158- Mac48Address src_mac = eeh_1.GetSource ();
159- Mac48Address dst_mac = eeh_1.GetDestination ();
160- uint16_t protocol_eth = eeh_1.GetLengthType ();
161- NS_LOG_DEBUG (" * Ethernet header: Source MAC: " << src_mac << " , Destination MAC: " << dst_mac
162- << " , Protocol: " << protocol_eth);
163- }
164-
165- // check if ipv4 packet
166- Ipv4Header ip_hd;
167- if (ns3Packet->PeekHeader (ip_hd))
168- {
169- NS_LOG_DEBUG (" IPv4 packet" );
170- // log the ipv4 header information
171- Ipv4Address src_ip = ip_hd.GetSource ();
172- Ipv4Address dst_ip = ip_hd.GetDestination ();
173- uint8_t protocol_ip = ip_hd.GetProtocol ();
174- uint8_t ttl_ip = ip_hd.GetTtl ();
175- uint16_t id_ip = ip_hd.GetIdentification ();
176- uint16_t len_ip = ip_hd.GetPayloadSize ();
177- uint16_t frag_ip = ip_hd.GetFragmentOffset ();
178- NS_LOG_DEBUG (" ** Ipv4 header: Source IP: "
179- << src_ip << " , Destination IP: " << dst_ip
180- << " , Protocol: " << static_cast <uint32_t > (protocol_ip)
181- << ", TTL: " << static_cast<uint32_t> (ttl_ip) << ", ID: " << id_ip
182- << ", Length: " << len_ip << ", Fragment Offset: " << frag_ip);
183- // std::cout << "** Ipv4 header: Source IP: " << src_ip << ", Destination IP: " << dst_ip
184- // << ", Protocol: " << static_cast<uint32_t> (protocol_ip)
185- // << ", TTL: " << static_cast<uint32_t> (ttl_ip) << ", ID: " << id_ip
186- // << ", Length: " << len_ip << ", Fragment Offset: " << frag_ip << std::endl;
216+ ns3Packet->RemoveHeader (eeh_1);
187217 }
188-
189- // check if arp packet
190- ArpHeader arp_hd;
191- if (ns3Packet->PeekHeader (arp_hd))
192- {
193- NS_LOG_DEBUG (" ARP packet" );
194- // log the arp header information
195- Address src_mac = arp_hd.GetSourceHardwareAddress ();
196- Address dst_mac = arp_hd.GetDestinationHardwareAddress ();
197- Ipv4Address src_ip = arp_hd.GetSourceIpv4Address ();
198- Ipv4Address dst_ip = arp_hd.GetDestinationIpv4Address ();
199- NS_LOG_DEBUG (" ** Arp header: Source MAC: " << src_mac << " , Destination MAC: " << dst_mac
200- << " , Source IP: " << src_ip
201- << " , Destination IP: " << dst_ip);
202- // std::cout << "** Arp header: Source MAC: " << src_mac << ", Destination MAC: " << dst_mac
203- // << ", Source IP: " << src_ip << ", Destination IP: " << dst_ip << std::endl;
204- }
205-
206- // Add ethernet header for the packet, this is because the csma-net-device for each port will remove the
207- // ethernet header, so we add another ethernet header, avoid modifications to existing mods.
208218 eeh_1.SetDestination (dst48);
209219 eeh_1.SetSource (src48);
210- eeh_1.SetLengthType (protocol);
220+ // eeh_1.SetLengthType (protocol); // Keep the protocol number
211221 std::cout << " * Modified Ethernet header: Source MAC: " << eeh_1.GetSource ()
212222 << " , Destination MAC: " << eeh_1.GetDestination ()
213223 << " , Protocol: " << eeh_1.GetLengthType () << std::endl;
214224 ns3Packet->AddHeader (eeh_1);
215225
226+ std::cout << " ns3::BridgeP4NetDevice::ReceiveFromDevice After changing header with MAC address"
227+ << std::endl;
228+ ns3Packet->Print (std::cout);
229+ std::cout << " " << std::endl;
230+
216231 m_p4Switch->ReceivePacket (ns3Packet, inPort, protocol, dst);
217232}
218233
@@ -435,6 +450,10 @@ BridgeP4NetDevice::SendNs3Packet (Ptr<Packet> packetOut, int outPort, uint16_t p
435450 NS_LOG_DEBUG (" Sending ns3 packet to port " << outPort);
436451 if (packetOut)
437452 {
453+ std::cout << " Bridge send out with packet lenghttttttth " << packetOut->GetSize ()
454+ << std::endl;
455+ packetOut->Print (std::cout);
456+ std::cout << " " << std::endl;
438457
439458 EthernetHeader eeh_1;
440459 if (packetOut->PeekHeader (eeh_1))
@@ -444,48 +463,52 @@ BridgeP4NetDevice::SendNs3Packet (Ptr<Packet> packetOut, int outPort, uint16_t p
444463 Mac48Address src_mac = eeh_1.GetSource ();
445464 Mac48Address dst_mac = eeh_1.GetDestination ();
446465 uint16_t protocol_eth = eeh_1.GetLengthType ();
466+ protocol = protocol_eth;
447467 NS_LOG_DEBUG (" Source MAC: " << src_mac << " , Destination MAC: " << dst_mac
448468 << " , Protocol: " << protocol_eth);
449- // std::cout << "<= Ethernet header: Source MAC: " << src_mac
450- // << ", Destination MAC: " << dst_mac << ", Protocol: " << protocol_eth
451- // << std::endl;
469+ std::cout << " SEND:: <= Ethernet header: Source MAC: " << src_mac
470+ << " , Destination MAC: " << dst_mac << " , Protocol: " << protocol_eth
471+ << std::endl;
452472 }
453473
454474 EthernetHeader eeh;
455- packetOut->RemoveHeader (eeh);
456-
457- Ipv4Header ip_hd;
458- if (packetOut->PeekHeader (ip_hd))
459- {
460- NS_LOG_DEBUG (" IPv4 packet" );
461- // log the ipv4 header information
462- Ipv4Address src_ip = ip_hd.GetSource ();
463- Ipv4Address dst_ip = ip_hd.GetDestination ();
464- uint8_t protocol_ip = ip_hd.GetProtocol ();
465- uint8_t ttl_ip = ip_hd.GetTtl ();
466- uint16_t id_ip = ip_hd.GetIdentification ();
467- uint16_t len_ip = ip_hd.GetPayloadSize ();
468- uint16_t frag_ip = ip_hd.GetFragmentOffset ();
469- NS_LOG_DEBUG (" Source IP: " << src_ip << " , Destination IP: " << dst_ip
470- << " , Protocol: " << static_cast <uint32_t > (protocol_ip)
471- << ", TTL: " << static_cast<uint32_t> (ttl_ip)
472- << ", ID: " << id_ip << ", Length: " << len_ip
473- << ", Fragment Offset: " << frag_ip);
474- }
475-
476- ArpHeader arp_hd;
477- if (packetOut->PeekHeader (arp_hd))
478- {
479- NS_LOG_DEBUG (" ARP packet" );
480- // log the arp header information
481- Address src_mac = arp_hd.GetSourceHardwareAddress ();
482- Address dst_mac = arp_hd.GetDestinationHardwareAddress ();
483- Ipv4Address src_ip = arp_hd.GetSourceIpv4Address ();
484- Ipv4Address dst_ip = arp_hd.GetDestinationIpv4Address ();
485- NS_LOG_DEBUG (" Source MAC: " << src_mac << " , Destination MAC: " << dst_mac
486- << " , Source IP: " << src_ip
487- << " , Destination IP: " << dst_ip);
488- }
475+ packetOut->RemoveHeader (eeh); // keep the ethernet header
476+
477+ // packetOut->Print (std::cout);
478+ // std::cout << " " << std::endl;
479+
480+ // Ipv4Header ip_hd;
481+ // if (packetOut->PeekHeader (ip_hd))
482+ // {
483+ // NS_LOG_DEBUG ("IPv4 packet");
484+ // // log the ipv4 header information
485+ // Ipv4Address src_ip = ip_hd.GetSource ();
486+ // Ipv4Address dst_ip = ip_hd.GetDestination ();
487+ // uint8_t protocol_ip = ip_hd.GetProtocol ();
488+ // uint8_t ttl_ip = ip_hd.GetTtl ();
489+ // uint16_t id_ip = ip_hd.GetIdentification ();
490+ // uint16_t len_ip = ip_hd.GetPayloadSize ();
491+ // uint16_t frag_ip = ip_hd.GetFragmentOffset ();
492+ // NS_LOG_DEBUG ("Source IP: " << src_ip << ", Destination IP: " << dst_ip
493+ // << ", Protocol: " << static_cast<uint32_t> (protocol_ip)
494+ // << ", TTL: " << static_cast<uint32_t> (ttl_ip)
495+ // << ", ID: " << id_ip << ", Length: " << len_ip
496+ // << ", Fragment Offset: " << frag_ip);
497+ // }
498+
499+ // ArpHeader arp_hd;
500+ // if (packetOut->PeekHeader (arp_hd))
501+ // {
502+ // NS_LOG_DEBUG ("ARP packet");
503+ // // log the arp header information
504+ // Address src_mac = arp_hd.GetSourceHardwareAddress ();
505+ // Address dst_mac = arp_hd.GetDestinationHardwareAddress ();
506+ // Ipv4Address src_ip = arp_hd.GetSourceIpv4Address ();
507+ // Ipv4Address dst_ip = arp_hd.GetDestinationIpv4Address ();
508+ // NS_LOG_DEBUG ("Source MAC: " << src_mac << ", Destination MAC: " << dst_mac
509+ // << ", Source IP: " << src_ip
510+ // << ", Destination IP: " << dst_ip);
511+ // }
489512
490513 if (outPort != 511 )
491514 {
0 commit comments