Search in sources :

Example 11 with ICMP

use of org.onlab.packet.ICMP 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 12 with ICMP

use of org.onlab.packet.ICMP 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 13 with ICMP

use of org.onlab.packet.ICMP 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 14 with ICMP

use of org.onlab.packet.ICMP 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)

Example 15 with ICMP

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

the class OpenstackTroubleshootManager method constructIcmpPacket.

/**
 * Constructs an ICMP packet with given source and destination IP/MAC.
 *
 * @param srcIp     source IP address
 * @param dstIp     destination IP address
 * @param srcMac    source MAC address
 * @param dstMac    destination MAC address
 * @param icmpId    ICMP identifier
 * @param icmpSeq   ICMP sequence number
 * @return an ethernet frame which contains ICMP payload
 */
private Ethernet constructIcmpPacket(IpAddress srcIp, IpAddress dstIp, MacAddress srcMac, MacAddress dstMac, short icmpId, short icmpSeq) {
    // Ethernet frame
    Ethernet ethFrame = new Ethernet();
    ethFrame.setEtherType(TYPE_IPV4);
    ethFrame.setSourceMACAddress(srcMac);
    ethFrame.setDestinationMACAddress(dstMac);
    // IP packet
    IPv4 iPacket = new IPv4();
    iPacket.setDestinationAddress(dstIp.toString());
    iPacket.setSourceAddress(srcIp.toString());
    iPacket.setTtl(TTL);
    iPacket.setProtocol(IPv4.PROTOCOL_ICMP);
    // ICMP packet
    ICMP icmp = new ICMP();
    icmp.setIcmpType(TYPE_ECHO_REQUEST).setIcmpCode(TYPE_ECHO_REQUEST).resetChecksum();
    // ICMP ECHO packet
    ICMPEcho icmpEcho = new ICMPEcho();
    icmpEcho.setIdentifier(icmpId).setSequenceNum(icmpSeq);
    ByteBuffer byteBufferIcmpEcho = ByteBuffer.wrap(icmpEcho.serialize());
    try {
        icmp.setPayload(ICMPEcho.deserializer().deserialize(byteBufferIcmpEcho.array(), 0, ICMPEcho.ICMP_ECHO_HEADER_LENGTH));
    } catch (DeserializationException e) {
        log.warn("Failed to deserialize ICMP ECHO REQUEST packet");
    }
    ByteBuffer byteBufferIcmp = ByteBuffer.wrap(icmp.serialize());
    try {
        iPacket.setPayload(ICMP.deserializer().deserialize(byteBufferIcmp.array(), 0, byteBufferIcmp.array().length));
    } catch (DeserializationException e) {
        log.warn("Failed to deserialize ICMP packet");
    }
    ethFrame.setPayload(iPacket);
    return ethFrame;
}
Also used : ICMPEcho(org.onlab.packet.ICMPEcho) Ethernet(org.onlab.packet.Ethernet) IPv4(org.onlab.packet.IPv4) ByteBuffer(java.nio.ByteBuffer) DeserializationException(org.onlab.packet.DeserializationException) ICMP(org.onlab.packet.ICMP)

Aggregations

ICMP (org.onlab.packet.ICMP)23 IPv4 (org.onlab.packet.IPv4)20 Ethernet (org.onlab.packet.Ethernet)19 Test (org.junit.Test)10 ICMP6 (org.onlab.packet.ICMP6)5 ICMPEcho (org.onlab.packet.ICMPEcho)5 IPv6 (org.onlab.packet.IPv6)5 IpAddress (org.onlab.packet.IpAddress)5 MPLS (org.onlab.packet.MPLS)5 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)5 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)5 ByteBuffer (java.nio.ByteBuffer)4 ConnectPoint (org.onosproject.net.ConnectPoint)4 DeviceId (org.onosproject.net.DeviceId)4 Objects (java.util.Objects)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 Ip4Address (org.onlab.packet.Ip4Address)3 MacAddress (org.onlab.packet.MacAddress)3 VlanId (org.onlab.packet.VlanId)3