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());
}
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;
}
}
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());
}
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());
}
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;
}
Aggregations