Software Defined Networking
cancel
Showing results for 
Search instead for 
Did you mean: 

How do I assemble and send a packet from a SDN App for the HP VAN controller

 
Highlighted
Frequent Advisor

How do I assemble and send a packet from a SDN App for the HP VAN controller

I've been on the HP SDN App course, I'm now trying to write a very basic packet in / packet out app, where I can ping the controller on the SDN network side.

 

I can handle a ICMP ech request packet, decode it to ethernet, IP and ICMP and then modify the fields, e.g.

 

public boolean action (MessageContext messageContext, Packet packetInData)
    {

        // Extract the Ethernet packet info.
        Ethernet  ethData        = packetInData.get( ProtocolId.ETHERNET );
        MacAddress srcMacAddr    = ethData.srcAddr();
        MacAddress dstMacAddr    = ethData.dstAddr();
        ProtocolId ethProtocol    = ethData.id();
        int ethLength            = ethData.len();
        EthernetType ethType    = ethData.type();
        Ethernet.SnapId ethSnap = ethData.snapId();
        Ethernet.Control ethCtl = ethData.control();
        Ethernet.Ssap ethSsap    = ethData.ssap();
        Ethernet.Dsap ethDsap    = ethData.dsap();
        
        // Extract IP packet info
        Ip        ipData        = packetInData.get( ProtocolId.IP );
        IpAddress srcIpAddress     = ipData.srcAddr();
        IpAddress dstIpAddress     = ipData.dstAddr();
        ProtocolId ipProtocol    = ipData.id();
        int ipTTL                = ipData.ttl();
        
        // Extract ICMP info
        Icmp icmpData            = packetInData.get( ProtocolId.ICMP);
        int icmpIdent            = icmpData.ident();
        int icmpSeqNumber        = icmpData.seqNum();
        IcmpTypeCode icmpType    = icmpData.typeCode();
        //String packetString    = icmpData.toString();
        byte[] icmpPayload        = icmpData.bytes();
        
       
        // Build response packet
        // Build ICMP response based on original ICMP packet
        Icmp.Builder icmpOutData = new Icmp.Builder(icmpData);
        icmpOutData.ident(icmpIdent);
        icmpOutData.typeCode(IcmpTypeCode.valueOf("ECHO_REPLY"));
        icmpOutData.seqNum(icmpSeqNumber);
        
        // IP response packet based on original IP packet
        Ip.Builder ipOutData = new Ip.Builder(ipData);
        ipOutData.dstAddr(srcIpAddress);
        ipOutData.srcAddr(dstIpAddress);
        ipOutData.ident(icmpIdent);
        ipOutData.ttl(255);
            
        // Ethernet response frame based on original Ethernet frame
        Ethernet.Builder ethOutData = new Ethernet.Builder(ethData);
        ethOutData.control(ethCtl);
        ethOutData.snapId(ethSnap);
        ethOutData.type(ethType);
        ethOutData.ssap(ethSsap);
        ethOutData.dsap(ethDsap);
        ethOutData.dstAddr(srcMacAddr);
        ethOutData.srcAddr(dstMacAddr);
       
        // Assemble packet
        Packet packetOutData = new Packet();
       
        return true;
    }

 

How do combine the ethernet, IP and ICMP parts into a new packet and send the packet back to the switch?

 

Which classes do I use?

 

Any help appreciated.

 

Dave.

5 REPLIES 5
Highlighted
Trusted Contributor

Re: How do I assemble and send a packet from a SDN App for the HP VAN controller

Hello Dave,

 

Apologies for the delay.

Did you try to use Packet Class (from the package com.hp.util.pkt.Packet)?

This class has constructors as below

 

Packet(List<Protocol> layers)

Constructor creates a packet of protocol layers.

 

Packet(Protocol... layers)

Constructor creates a packet of protocol layers.

Here Protocols are Ethernet,Icmp,Ip,…

 

So different protocols can be combined in the List to create the packet.

Please let us know if you are still facing the issue or your problem is solved.

 

Thanks,

HP SDN Team

Highlighted
Frequent Advisor

Re: How do I assemble and send a packet from a SDN App for the HP VAN controller

Thanks for the reply,

 

I am using the Packet Class (from the package com.hp.util.pkt.Packet)

import com.hp.util.pkt.Packet; 

 

When I try to create a packet I get the error message:

 

"The constructor Packet(Ethernet.Builder, Ip.Builder, Tcp.Builder, Icmp.Builder) is undefined."

 

 

I am modified the Eth, IP , TCP and ICMP info using:

 

        // Build ICMP response based on original ICMP packet
        Icmp.Builder icmpOutData = new Icmp.Builder(icmpData);
        icmpOutData.ident(icmpIdent);
        icmpOutData.typeCode(IcmpTypeCode.valueOf("ECHO_REPLY"));
        icmpOutData.seqNum(icmpSeqNumber);
        
        // IP response packet based on original IP packet
        Ip.Builder ipOutData = new Ip.Builder(ipData);
        ipOutData.dstAddr(srcIpAddress);
        ipOutData.srcAddr(dstIpAddress);
        ipOutData.ident(icmpIdent);
        ipOutData.ttl(255);

        // TCP response
        Tcp.Builder tcpOutData = new Tcp.Builder(tcpData);
        tcpOutData.dstPort(srcTCPport);
        tcpOutData.dstPort(dstTCPport);
        
        // Ethernet response frame based on original Ethernet frame
        Ethernet.Builder ethOutData = new Ethernet.Builder(ethData);
        ethOutData.control(ethCtl);
        ethOutData.snapId(ethSnap);
        ethOutData.type(ethType);
        ethOutData.ssap(ethSsap);
        ethOutData.dsap(ethDsap);
        ethOutData.dstAddr(srcMacAddr);
        ethOutData.srcAddr(dstMacAddr);

 

        // Assemble packet
        Packet packetOutData = new Packet(ethOutData, ipOutData, tcpOutData, icmpOutData);

 

 

 

Dave.

Highlighted
Frequent Advisor

Re: How do I assemble and send a packet from a SDN App for the HP VAN controller

A more specifc question would be how to convert back from mutable Ethernet.Builder / Ip.Builder / Icmp.builder classes to the  immutable Ethernet / Ip / Icmp classes.

 

To  create a packet I can use;

 

Packet MyPacket = new Packet(eth, ip, icmp);

 

# There is no tcp layer for ICMP packets.

 

However to modify or create eth, ip and icmp inner layers I have to create mutable versions , e.g.

 

  Icmp.Builder icmpOutData = new Icmp.Builder(icmpData);

 

But I cannot use icmpOutData when I create a new packet or cast to Icmp.

 

 

Dave.

Highlighted
Trusted Contributor

Re: How do I assemble and send a packet from a SDN App for the HP VAN controller

Hello Dave,

 

Apologies for the delay.

Please let us know if your problem is solved or you still facing some issue.


If you have more questions on the same topic please do reply on the same thread or open a new post if new topic.

 

Thanks,
HP SDN Team

Highlighted
Frequent Advisor

Re: How do I assemble and send a packet from a SDN App for the HP VAN controller

SDN Team,

 

I still haven't been able to create and output packets in HP VAN 2.0.

 

I have started setting up a HP VAN 2.3 developement system, but not finished this yet.

 

I also do not know if either HP VAN 2.0 or 2.3 are capable of creating and sending a packet to a switch.

 

It would aslo be useful if there were IGMP packet functions in the SDK. Multicast is very important for my industry.

 

Dave.