SD-WAN

 View Only
  • 1.  Creating and Inspecting DHCP packets in VAN

    Posted May 17, 2017 03:10 PM

    Hi there, 

    we would like to implement a simple DHCP server module in our controller (v2.7.18). Since DHCP is not part of OpenFlow protocol, we have to inspect the payload to get the relevant data to form DHCP offer/ack messages. Here's the workflow we are following:

    1. Create a rule that matches on UDP_SRC/DST 67/68 and send it to the controller (DONE)

    2.  Use OfmPacketIn.getData() to extract payload and access the byte[] to get relevant data (like XID, Hardware Address, etc). Not my favorite task, but doable.  (DONE -- but it would be nice to be able to create a DHCP object from the raw data, and then use a static class to access the fields). 

    3. Create a packetout that contains the DHCP response. VAN's API has a DHCP and DHCP.Builder classes that I assume are target to this case. I am able to create a DHCP instance but I cannot figure out how to add it to the payload of the packetout message I am building.

    Do I need to use Java's built-in libraries to serialize objects like::

    public static byte[] serialize(Dhcp pkt) throws IOException {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ObjectOutputStream os = new ObjectOutputStream(out);    os.writeObject(pkt);
        return out.toByteArray();
    }
    

    Is there a different way to do it?

    Thanks in advance for your suggestions! 


    #DHCP
    #VAN


  • 2.  RE: Creating and Inspecting DHCP packets in VAN

    Posted May 18, 2017 08:41 PM

    Hi checho,

    For packet types which VAN is able to recognize and parse (DHCP is one of them), you can use com.hp.util.pkt.Codec.decodeEthernet(byte[]) to decode a byte array into a Packet. The Packet will have accessors to get each header layer, so in this case you'd want to call Packet.get(ProtocolId.DHCP).

    To create a packet-out message, you'll start with the Dhcp object that you created using Dhcp.Builder. Then you'd call com.hp.util.pkt.Codec.encode(Dhcp) which returns a byte[]. From there, you'd get the byte[] into the packet-out message by building the packet-out message. It would look something like this:

    Dhcp.Builder builder = new Dhcp.Builder();
    // .. build DHCP fields ..
    Dhcp dhcp = builder.build();

    OfmMutablePacketOut po = (OfmMutablePacketOut) MessageFactory.create(pv, MessageType.PACKET_OUT); po.bufferId(BufferId.NO_BUFFER); po.inPort(Port.CONTROLLER); // Required by OF spec po.addAction(ActionFactory.createAction(pv, ActionType.OUTPUT, bpn, ActOutput.CONTROLLER_NO_BUFFER)); po.data(Codec.encode(dhcp));

    Could you try this out and let us know if it works for you?

    Shaun



  • 3.  RE: Creating and Inspecting DHCP packets in VAN

    Posted May 20, 2017 10:08 AM

    Shaun, thank you for your response. This is great news and does make things more intuitive to code. Once we have a usable version of the module, I will post here if en/decoding worked as it should.