Search in sources :

Example 1 with ICMPEcho

use of org.onlab.packet.ICMPEcho in project onos by opennetworkinglab.

the class OpenstackRoutingSnatIcmpHandlerTest method validateIcmpReqToGw.

private void validateIcmpReqToGw(IPv4 ipPacket) {
    ICMP icmpReq = (ICMP) ipPacket.getPayload();
    ICMPEcho icmpEchoReq = (ICMPEcho) icmpReq.getPayload();
    short icmpId = icmpEchoReq.getIdentifier();
    short seqNum = icmpEchoReq.getSequenceNum();
    assertEquals(icmpReq.getIcmpType(), TYPE_ECHO_REPLY);
    assertEquals(icmpReq.getIcmpCode(), CODE_ECHO_REPLY);
    assertEquals(icmpId, 0);
    assertEquals(seqNum, 0);
    assertEquals(IPv4.fromIPv4Address(ipPacket.getSourceAddress()), targetIpToGw.toString());
    assertEquals(IPv4.fromIPv4Address(ipPacket.getDestinationAddress()), srcIpPort1.toString());
}
Also used : ICMPEcho(org.onlab.packet.ICMPEcho) ICMP(org.onlab.packet.ICMP)

Example 2 with ICMPEcho

use of org.onlab.packet.ICMPEcho in project onos by opennetworkinglab.

the class OpenstackTroubleshootManager method icmpId.

/**
 * Obtains an unique ICMP key.
 *
 * @param icmp ICMP packet
 * @return  ICMP key
 */
private String icmpId(ICMP icmp) {
    ICMPEcho echo = (ICMPEcho) icmp.getPayload();
    checkNotNull(echo);
    short icmpId = echo.getIdentifier();
    return String.valueOf(icmpId);
}
Also used : ICMPEcho(org.onlab.packet.ICMPEcho)

Example 3 with ICMPEcho

use of org.onlab.packet.ICMPEcho in project onos by opennetworkinglab.

the class OpenstackRoutingSnatIcmpHandlerTest method validateIcmpRespFromExternal.

private void validateIcmpRespFromExternal(IPv4 ipPacket) {
    ICMP icmpResp = (ICMP) ipPacket.getPayload();
    ICMPEcho icmpEchoResp = (ICMPEcho) icmpResp.getPayload();
    short icmpId = icmpEchoResp.getIdentifier();
    short seqNum = icmpEchoResp.getSequenceNum();
    assertEquals(icmpResp.getIcmpType(), TYPE_ECHO_REPLY);
    assertEquals(icmpResp.getIcmpCode(), CODE_ECHO_REPLY);
    assertEquals(icmpId, 0);
    assertEquals(seqNum, 0);
    assertEquals(IPv4.fromIPv4Address(ipPacket.getSourceAddress()), targetIpToExternal.toString());
    assertEquals(IPv4.fromIPv4Address(ipPacket.getDestinationAddress()), srcIpPort1.toString());
}
Also used : ICMPEcho(org.onlab.packet.ICMPEcho) ICMP(org.onlab.packet.ICMP)

Example 4 with ICMPEcho

use of org.onlab.packet.ICMPEcho in project onos by opennetworkinglab.

the class OpenstackRoutingSnatIcmpHandlerTest method constructIcmpRequestPacket.

private Ethernet constructIcmpRequestPacket(IpAddress srcIp, MacAddress srcMac, IpAddress dstIp, MacAddress dstMac, byte icmpType) {
    try {
        ICMPEcho icmpEcho = new ICMPEcho();
        icmpEcho.setIdentifier((short) 0).setSequenceNum((short) 0);
        ByteBuffer byteBufferIcmpEcho = ByteBuffer.wrap(icmpEcho.serialize());
        ICMP icmp = new ICMP();
        icmp.setIcmpType(icmpType).setIcmpCode(icmpType == TYPE_ECHO_REQUEST ? CODE_ECHO_REQUEST : CODE_ECHO_REPLY).setChecksum((short) 0);
        icmp.setPayload(ICMPEcho.deserializer().deserialize(byteBufferIcmpEcho.array(), 0, ICMPEcho.ICMP_ECHO_HEADER_LENGTH));
        ByteBuffer byteBufferIcmp = ByteBuffer.wrap(icmp.serialize());
        IPv4 iPacket = new IPv4();
        iPacket.setDestinationAddress(dstIp.toString());
        iPacket.setSourceAddress(srcIp.toString());
        iPacket.setTtl((byte) 64);
        iPacket.setChecksum((short) 0);
        iPacket.setDiffServ((byte) 0);
        iPacket.setProtocol(IPv4.PROTOCOL_ICMP);
        iPacket.setPayload(ICMP.deserializer().deserialize(byteBufferIcmp.array(), 0, 8));
        Ethernet ethPacket = new Ethernet();
        ethPacket.setEtherType(TYPE_IPV4);
        ethPacket.setSourceMACAddress(srcMac);
        ethPacket.setDestinationMACAddress(dstMac);
        ethPacket.setPayload(iPacket);
        return ethPacket;
    } catch (DeserializationException e) {
        return null;
    }
}
Also used : ICMPEcho(org.onlab.packet.ICMPEcho) IPv4(org.onlab.packet.IPv4) Ethernet(org.onlab.packet.Ethernet) ByteBuffer(java.nio.ByteBuffer) DeserializationException(org.onlab.packet.DeserializationException) ICMP(org.onlab.packet.ICMP)

Example 5 with ICMPEcho

use of org.onlab.packet.ICMPEcho in project onos by opennetworkinglab.

the class OpenstackRoutingSnatIcmpHandlerTest method validateIcmpReqToExternal.

private void validateIcmpReqToExternal(IPv4 ipPacket) {
    ICMP icmpReq = (ICMP) ipPacket.getPayload();
    ICMPEcho icmpEchoReq = (ICMPEcho) icmpReq.getPayload();
    short icmpId = icmpEchoReq.getIdentifier();
    short seqNum = icmpEchoReq.getSequenceNum();
    assertEquals(icmpReq.getIcmpType(), TYPE_ECHO_REQUEST);
    assertEquals(icmpReq.getIcmpCode(), CODE_ECHO_REQUEST);
    assertEquals(icmpId, 0);
    assertEquals(seqNum, 0);
    assertEquals(IPv4.fromIPv4Address(ipPacket.getSourceAddress()), sNatIp.toString());
    assertEquals(IPv4.fromIPv4Address(ipPacket.getDestinationAddress()), targetIpToExternal.toString());
}
Also used : ICMPEcho(org.onlab.packet.ICMPEcho) ICMP(org.onlab.packet.ICMP)

Aggregations

ICMPEcho (org.onlab.packet.ICMPEcho)6 ICMP (org.onlab.packet.ICMP)5 ByteBuffer (java.nio.ByteBuffer)2 DeserializationException (org.onlab.packet.DeserializationException)2 Ethernet (org.onlab.packet.Ethernet)2 IPv4 (org.onlab.packet.IPv4)2