View | Details | Raw Unified | Return to bug 1557
Collapse All | Expand All

(-)a/src/openflow/model/openflow-switch-net-device.cc (-14 / +15 lines)
 Lines 444-453    Link Here 
444
}
444
}
445
445
446
ofpbuf *
446
ofpbuf *
447
OpenFlowSwitchNetDevice::BufferFromPacket (Ptr<Packet> packet, Address src, Address dst, int mtu, uint16_t protocol)
447
OpenFlowSwitchNetDevice::BufferFromPacket (Ptr<const Packet> constPacket, Address src, Address dst, int mtu, uint16_t protocol)
448
{
448
{
449
  NS_LOG_INFO ("Creating Openflow buffer from packet.");
449
  NS_LOG_INFO ("Creating Openflow buffer from packet.");
450
450
451
  Ptr<Packet> packet = constPacket->Copy ();
451
  /*
452
  /*
452
   * Allocate buffer with some headroom to add headers in forwarding
453
   * Allocate buffer with some headroom to add headers in forwarding
453
   * to the controller or adding a vlan tag, plus an extra 2 bytes to
454
   * to the controller or adding a vlan tag, plus an extra 2 bytes to
 Lines 460-478    Link Here 
460
461
461
  int l2_length = 0, l3_length = 0, l4_length = 0;
462
  int l2_length = 0, l3_length = 0, l4_length = 0;
462
463
463
  // Load headers
464
  //Parse Ethernet header
464
  EthernetHeader eth_hd;
465
  buffer->l2 = new eth_header;
465
  if (packet->PeekHeader (eth_hd))
466
  eth_header* eth_h = (eth_header*)buffer->l2;
466
    {
467
  dst.CopyTo (eth_h->eth_dst);              // Destination Mac Address
467
      buffer->l2 = new eth_header;
468
  src.CopyTo (eth_h->eth_src);              // Source Mac Address
468
      eth_header* eth_h = (eth_header*)buffer->l2;
469
  eth_h->eth_type = htons (ETH_TYPE_IP);    // Ether Type
469
      dst.CopyTo (eth_h->eth_dst);              // Destination Mac Address
470
  NS_LOG_INFO ("Parsed EthernetHeader");
470
      src.CopyTo (eth_h->eth_src);              // Source Mac Address
471
      eth_h->eth_type = htons (ETH_TYPE_IP);    // Ether Type
472
      NS_LOG_INFO ("Parsed EthernetHeader");
473
471
474
      l2_length = ETH_HEADER_LEN;
472
  l2_length = ETH_HEADER_LEN;
475
    }
476
473
477
  // We have to wrap this because PeekHeader has an assert fail if we check for an Ipv4Header that isn't there.
474
  // We have to wrap this because PeekHeader has an assert fail if we check for an Ipv4Header that isn't there.
478
  if (protocol == Ipv4L3Protocol::PROT_NUMBER)
475
  if (protocol == Ipv4L3Protocol::PROT_NUMBER)
 Lines 493-498    Link Here 
493
          ip_h->ip_dst      = htonl (ip_hd.GetDestination ().Get ()); // Destination Address
490
          ip_h->ip_dst      = htonl (ip_hd.GetDestination ().Get ()); // Destination Address
494
          ip_h->ip_csum     = csum (&ip_h, sizeof ip_h);        // Header Checksum
491
          ip_h->ip_csum     = csum (&ip_h, sizeof ip_h);        // Header Checksum
495
          NS_LOG_INFO ("Parsed Ipv4Header");
492
          NS_LOG_INFO ("Parsed Ipv4Header");
493
          packet->RemoveHeader (ip_hd);
496
494
497
          l3_length = IP_HEADER_LEN;
495
          l3_length = IP_HEADER_LEN;
498
        }
496
        }
 Lines 515-520    Link Here 
515
          arp_h->ar_hln = sizeof arp_h->ar_tha;                         // Hardware address length.
513
          arp_h->ar_hln = sizeof arp_h->ar_tha;                         // Hardware address length.
516
          arp_h->ar_pln = sizeof arp_h->ar_tpa;                         // Protocol address length.
514
          arp_h->ar_pln = sizeof arp_h->ar_tpa;                         // Protocol address length.
517
          NS_LOG_INFO ("Parsed ArpHeader");
515
          NS_LOG_INFO ("Parsed ArpHeader");
516
          packet->RemoveHeader (arp_hd);
518
517
519
          l3_length = ARP_ETH_HEADER_LEN;
518
          l3_length = ARP_ETH_HEADER_LEN;
520
        }
519
        }
 Lines 539-544    Link Here 
539
              tcp_h->tcp_urg = tcp_hd.GetUrgentPointer ();      // Urgent Pointer
538
              tcp_h->tcp_urg = tcp_hd.GetUrgentPointer ();      // Urgent Pointer
540
              tcp_h->tcp_csum = csum (&tcp_h, sizeof tcp_h);    // Header Checksum
539
              tcp_h->tcp_csum = csum (&tcp_h, sizeof tcp_h);    // Header Checksum
541
              NS_LOG_INFO ("Parsed TcpHeader");
540
              NS_LOG_INFO ("Parsed TcpHeader");
541
              packet->RemoveHeader (tcp_hd);
542
542
543
              l4_length = TCP_HEADER_LEN;
543
              l4_length = TCP_HEADER_LEN;
544
            }
544
            }
 Lines 562-574    Link Here 
562
              udp_csum = csum_continue (udp_csum, udp_h, sizeof udp_h);
562
              udp_csum = csum_continue (udp_csum, udp_h, sizeof udp_h);
563
              udp_h->udp_csum = csum_finish (csum_continue (udp_csum, buffer->data, buffer->size)); // Header Checksum
563
              udp_h->udp_csum = csum_finish (csum_continue (udp_csum, buffer->data, buffer->size)); // Header Checksum
564
              NS_LOG_INFO ("Parsed UdpHeader");
564
              NS_LOG_INFO ("Parsed UdpHeader");
565
              packet->RemoveHeader (udp_hd);
565
566
566
              l4_length = UDP_HEADER_LEN;
567
              l4_length = UDP_HEADER_LEN;
567
            }
568
            }
568
        }
569
        }
569
    }
570
    }
570
571
571
  // Load Packet data into buffer data
572
  // Load any remaining packet data into buffer data
572
  packet->CopyData ((uint8_t*)buffer->data, packet->GetSize ());
573
  packet->CopyData ((uint8_t*)buffer->data, packet->GetSize ());
573
574
574
  if (buffer->l4)
575
  if (buffer->l4)
(-)a/src/openflow/model/openflow-switch-net-device.h (-1 / +1 lines)
 Lines 268-274    Link Here 
268
   * \param protocol The protocol defining the packet.
268
   * \param protocol The protocol defining the packet.
269
   * \return The OpenFlow Buffer created from the packet.
269
   * \return The OpenFlow Buffer created from the packet.
270
   */
270
   */
271
  ofpbuf * BufferFromPacket (Ptr<Packet> packet, Address src, Address dst, int mtu, uint16_t protocol);
271
  ofpbuf * BufferFromPacket (Ptr<const Packet> packet, Address src, Address dst, int mtu, uint16_t protocol);
272
272
273
private:
273
private:
274
  /**
274
  /**

Return to bug 1557