SD-WAN

 View Only
  • 1.  create ARP reply (OpenFlow version 1.3 )

    Posted Mar 31, 2014 01:41 AM

    Hi

     

    I'm trying to create an ARP reply for OpenFlow 1.3 based on

     

    http://h30499.www3.hp.com/t5/SDN-Development/replying-ARP-message/m-p/6404080#M199

     

    but does not work

     

     

    my code is

    //------------------------------

    cs.addPacketListener(pl2, DIRECTOR, ALTITUDE2, EnumSet.of(ARP));

    //----------------------------------------------

     

    privateclass PacketListener2 extends SequencedPacketAdapter {

    @Override

    publicboolean event(MessageContext context) {

    Arp arpPkt = context.decodedPacket().get(ARP);

    if (arpPkt.opCode().equals(OpCode.REQ)) {

     

    if (is_a_rule(arpPkt.senderIpAddr(), arpPkt.senderMacAddr(), arpPkt.targetIpAddr(), context.getPacketIn()

    .getInPort(), context.srcEvent().dpid())) {

    return

    true;

    }

    }

    returnfalse;

    }

     

    privateboolean is_a_rule(IpAddress senderIpAddr,

    MacAddress senderMacAddr, IpAddress targetIpAddr,

    BigPortNumber inPort, DataPathId dpid) {

     

    .

    .

    .

    .

     

     

    Arp arpgen = build_arp(key);

    OfmMutablePacketOut packetout = (OfmMutablePacketOut) MessageFactory.create(ProtocolVersion.V_1_3, MessageType.PACKET_OUT);

    packetout.inPort(inPort);

    packetout.bufferId(BufferId.NO_BUFFER);

    packetout.data(arpgen.toString().getBytes());

    //packetout.addAction(act)  no ofv1.3

    try {

    cs.send(packetout.toImmutable(), dpid);

    log.info("arp packet was sent"

    + dpid.toString() + "de "

    + arpgen.targetIpAddr().toString());

    } catch (OpenflowException e) {

    // TODO Auto-generated catch block

    e.printStackTrace();

     

    returntrue;

     

     

    }

     

     

    the code does not generate any errors and on the log info appears "" arp packet was sent "" ,

     

     

     

    thanks for your help

     

     

     

     

     

     

     

     

     

     



  • 2.  RE: create ARP reply (OpenFlow version 1.3 )

    Posted Mar 31, 2014 05:51 PM

    @armandom wrote:

    packetout.data(arpgen.toString().getBytes());


    The above line is calling the getBytes() method from the String class[1], which doesn't structure the packet in the format
    specified by the protocol[2], so I guess the packet goes out but since the contents are not understood by other devices they discard them.

     

    [1] http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#getBytes%28%29

    [2] http://en.wikipedia.org/wiki/Address_Resolution_Protocol#Packet_structure



  • 3.  RE: create ARP reply (OpenFlow version 1.3 )

    Posted Apr 05, 2014 08:54 PM

    I made the changes you recommended me but did not work

     

    another idea?



  • 4.  RE: create ARP reply (OpenFlow version 1.3 )

    Posted Apr 14, 2014 04:03 PM

    Hi guys,

     

    Here is an ArpPacket class which I've created an ARP packet and how to create a PACKET_OUT message:

     

     

    ***** ARPPacket ******

     

    package example;

     

    import java.nio.ByteBuffer;
    import java.nio.ByteOrder;

     

    public class ArpPacket {
    private static final int ARP_RESPONSE = 2;
    private static final int HW_TYPE = 1;// ethernet
    private static final int PROTOCOL_TYPE = 0x0800;
    private static final int HW_ADDRESS_LENGHT = 6; // mac
    private static final int PROTOCOL_ADDRESS_LENGTH = 4; // ipv4

     

    public static byte[] createArpPacket(String srcIp, String srcMac,
    String dstIp, String dstMac) {
    byte[] sIp = new byte[4];
    byte[] sMac = new byte[6];
    byte[] dIp = new byte[4];
    byte[] dMac = new byte[6];

     

    System.out.println("ArpMessage: srcIp" + srcIp);
    for (int i = 0; i < 4; i++) {
    sIp[i] = (byte) Integer.parseInt(srcIp.split("\\.")[i]);
    }

     

    System.out.println("ArpMessage: srcMac" + srcMac);
    for (int i = 0; i < 6; i++) {
    sMac[i] = (byte) Integer.parseInt(srcMac.split(":")[i], 16);
    }

     

    System.out.println("ArpMessage: dstIp" + dstIp);
    for (int i = 0; i < 4; i++) {
    dIp[i] = (byte) Integer.parseInt(dstIp.split("\\.")[i]);
    }

     

    System.out.println("ArpMessage: dstMac" + dstMac);
    for (int i = 0; i < 6; i++) {
    dMac[i] = (byte) Integer.parseInt(dstMac.split(":")[i], 16);
    }

     

    //TODO: calculate exact packet length
    ByteBuffer buf = ByteBuffer.allocate(28+14);
    buf.clear();
    buf.order(ByteOrder.BIG_ENDIAN);

     

    buf.put(dMac);
    buf.put(sMac);
    buf.putShort((short) 0x0806);
    buf.putShort((short) HW_TYPE);
    buf.putShort((short) PROTOCOL_TYPE);
    buf.put((byte) HW_ADDRESS_LENGHT);
    buf.put((byte) PROTOCOL_ADDRESS_LENGTH);
    buf.putShort((short) ARP_RESPONSE);
    buf.put(sMac);
    buf.put(sIp);
    buf.put(dMac);
    buf.put(dIp);

     

    return buf.array();
    }
    }

     

    ******** PACKET_OUT***********

     

    OfmMutablePacketOut pOut = (OfmMutablePacketOut) MessageFactory.create(PV, MessageType.PACKET_OUT);

    byte[] arpResponse = ArpPacket.createArpPacket(IP_SERVER_VIRTUAL, MAC_SERVER_VIRTUAL,senderIp.toString(), senderMac.toString());

     

    System.out.println("SENDING TO SWITCH PORT: ["
    + senderIp.toString() + ":"
    + s.getPortToHost(senderIp.toString()) + "]");
    System.out.println("#################################");

    pOut.bufferId(BUFFER_ID)
    .inPort(Port.CONTROLLER)
    .data(arpResponse)
    .addAction(
    ActionFactory.createAction(PV,
    ActionType.OUTPUT, messageContext
    .getPacketIn().getInPort()));

     

     



  • 5.  RE: create ARP reply (OpenFlow version 1.3 )

    Posted Apr 18, 2014 11:37 AM

    HI   RichieKotzen

     

    I tested your code in my application but it did not work

     

    Can you use this code for OpenFlow version 1.3?

     

     because according to the api. addAction  is not used since 1.1

     

     

    thank you

     

    Captura de pantalla 2014-04-18 10.28.57.png



  • 6.  RE: create ARP reply (OpenFlow version 1.3 )

    Posted May 08, 2014 03:04 AM

    Hello armandom,

    We are looking into the issue and we will come back.

    Thanks,
    HP SDN Team



  • 7.  RE: create ARP reply (OpenFlow version 1.3 )

    Posted Jun 20, 2014 03:39 AM
      |   view attached

    Hello armandom,

     

    Please find the attached file DeviceHealthManager.java for sample ARP-Proxy App to send Arp-Reply.

    Currently ‘PROXY_MAC_ADDRESS’ and ‘ALTITUDE’ of the App are hardcoded.

    SDN Controller used :  2.2.5.0016

    SDN SDK used  : 2.2.5

    Hybrid mode of the controller : false

     

    Please let us know if you still face the problem.

     

     

    Thanks,

    HP SDN Team

    Attachment(s)

    txt
    DeviceHealthManager.txt   703 B 1 version