use of org.onlab.packet.ICMP in project onos by opennetworkinglab.
the class SimpleFabricRouting method checkVirtualGatewayIpPacket.
/**
* handle Packet with dstIp=virtualGatewayIpAddresses.
* returns true(handled) or false(not for virtual gateway)
*/
private boolean checkVirtualGatewayIpPacket(InboundPacket pkt, IpAddress srcIp, IpAddress dstIp) {
// assume valid
Ethernet ethPkt = pkt.parsed();
MacAddress mac = simpleFabric.vMacForIp(dstIp);
if (mac == null || !simpleFabric.isVirtualGatewayMac(ethPkt.getDestinationMAC())) {
/* Destination MAC should be any of virtual gateway macs */
return false;
} else if (dstIp.isIp4()) {
IPv4 ipv4Packet = (IPv4) ethPkt.getPayload();
if (ipv4Packet.getProtocol() == IPv4.PROTOCOL_ICMP) {
ICMP icmpPacket = (ICMP) ipv4Packet.getPayload();
if (icmpPacket.getIcmpType() == ICMP.TYPE_ECHO_REQUEST) {
log.info("IPV4 ICMP ECHO request to virtual gateway: " + "srcIp={} dstIp={} proto={}", srcIp, dstIp, ipv4Packet.getProtocol());
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(pkt.receivedFrom().port()).build();
OutboundPacket packet = new DefaultOutboundPacket(pkt.receivedFrom().deviceId(), treatment, ByteBuffer.wrap(icmpPacket.buildIcmpReply(pkt.parsed()).serialize()));
packetService.emit(packet);
return true;
}
}
log.warn("IPV4 packet to virtual gateway dropped: " + "srcIp={} dstIp={} proto={}", srcIp, dstIp, ipv4Packet.getProtocol());
return true;
} else if (dstIp.isIp6()) {
// TODO: not tested yet (2017-07-20)
IPv6 ipv6Packet = (IPv6) ethPkt.getPayload();
if (ipv6Packet.getNextHeader() == IPv6.PROTOCOL_ICMP6) {
ICMP6 icmp6Packet = (ICMP6) ipv6Packet.getPayload();
if (icmp6Packet.getIcmpType() == ICMP6.ECHO_REQUEST) {
log.info("IPV6 ICMP6 ECHO request to virtual gateway: srcIp={} dstIp={} nextHeader={}", srcIp, dstIp, ipv6Packet.getNextHeader());
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(pkt.receivedFrom().port()).build();
OutboundPacket packet = new DefaultOutboundPacket(pkt.receivedFrom().deviceId(), treatment, ByteBuffer.wrap(icmp6Packet.buildIcmp6Reply(pkt.parsed()).serialize()));
packetService.emit(packet);
return true;
}
}
log.warn("IPV6 packet to virtual gateway dropped: srcIp={} dstIp={} nextHeader={}", srcIp, dstIp, ipv6Packet.getNextHeader());
return true;
}
// unknown traffic
return false;
}
use of org.onlab.packet.ICMP in project trellis-control by opennetworkinglab.
the class IcmpHandlerTest method testPing4RemoteGatewaySamePair.
// Ping to a gateway attached only to the pair leaf (routing through spine)
@Test
public void testPing4RemoteGatewaySamePair() {
// Expected behavior
expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF1)).andReturn(true).times(1);
expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF2)).andReturn(true).times(1);
replay(segmentRoutingManager.deviceService);
// Process
icmpHandler.processIcmp(ETH_REQ_IPV4_SAME, CP2025);
// Verify packet-out
Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV4_SAME.getSourceMAC());
assertNotNull(ethernet);
assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV4_SAME.getDestinationMAC()));
assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV4_SAME.getSourceMAC()));
assertTrue(ethernet.getPayload() instanceof MPLS);
MPLS mpls = (MPLS) ethernet.getPayload();
assertThat(mpls.getLabel(), is(LOCAL_LEAF1_SID4));
assertTrue(mpls.getPayload() instanceof IPv4);
IPv4 ip = (IPv4) mpls.getPayload();
assertThat(ip.getSourceAddress(), is(DST_IPV4_SAME.toInt()));
assertThat(ip.getDestinationAddress(), is(SRC_IPV41.toInt()));
assertTrue(ip.getPayload() instanceof ICMP);
ICMP icmp = (ICMP) ip.getPayload();
assertThat(icmp.getIcmpType(), is(TYPE_ECHO_REPLY));
assertThat(icmp.getIcmpCode(), is(CODE_ECHO_REPLY));
// Verify behavior
verify(segmentRoutingManager.deviceService);
}
use of org.onlab.packet.ICMP in project trellis-control by opennetworkinglab.
the class IcmpHandlerTest method testPing4LoopbackPair.
// Ping to the looback of our leaf (pair)
@Test
public void testPing4LoopbackPair() {
// Expected behavior
expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF1)).andReturn(true).times(1);
expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF2)).andReturn(true).times(1);
replay(segmentRoutingManager.deviceService);
// Process
icmpHandler.processIcmp(ETH_REQ_IPV4_LOOPBACK_PAIR, CP2011);
// Verify packet-out
Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV4_LOOPBACK_PAIR.getSourceMAC());
assertNotNull(ethernet);
assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV4_LOOPBACK_PAIR.getDestinationMAC()));
assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV4_LOOPBACK_PAIR.getSourceMAC()));
assertTrue(ethernet.getPayload() instanceof IPv4);
IPv4 ip = (IPv4) ethernet.getPayload();
assertThat(ip.getSourceAddress(), is(DST_IPV4_LOOPBACK_PAIR.toInt()));
assertThat(ip.getDestinationAddress(), is(SRC_IPV41.toInt()));
assertTrue(ip.getPayload() instanceof ICMP);
ICMP icmp = (ICMP) ip.getPayload();
assertThat(icmp.getIcmpType(), is(TYPE_ECHO_REPLY));
assertThat(icmp.getIcmpCode(), is(CODE_ECHO_REPLY));
// Verify behavior
verify(segmentRoutingManager.deviceService);
}
use of org.onlab.packet.ICMP in project trellis-control by opennetworkinglab.
the class IcmpHandlerTest method testPing4LoopbackPairDifferentLeaf.
// Ping to the loopback of the leaf but hashing of the bond interfaces sends to wrong leaf
@Test
public void testPing4LoopbackPairDifferentLeaf() {
// Expected behavior
expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF1)).andReturn(true).times(1);
expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF2)).andReturn(true).times(1);
replay(segmentRoutingManager.deviceService);
// Process
icmpHandler.processIcmp(ETH_REQ_IPV4_LOOPBACK_PAIR, CP2021);
// Verify packet-out
Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV4_LOOPBACK_PAIR.getSourceMAC());
assertNotNull(ethernet);
assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV4_LOOPBACK_PAIR.getDestinationMAC()));
assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV4_LOOPBACK_PAIR.getSourceMAC()));
assertTrue(ethernet.getPayload() instanceof IPv4);
IPv4 ip = (IPv4) ethernet.getPayload();
assertThat(ip.getSourceAddress(), is(DST_IPV4_LOOPBACK_PAIR.toInt()));
assertThat(ip.getDestinationAddress(), is(SRC_IPV41.toInt()));
assertTrue(ip.getPayload() instanceof ICMP);
ICMP icmp = (ICMP) ip.getPayload();
assertThat(icmp.getIcmpType(), is(TYPE_ECHO_REPLY));
assertThat(icmp.getIcmpCode(), is(CODE_ECHO_REPLY));
// Verify behavior
verify(segmentRoutingManager.deviceService);
}
use of org.onlab.packet.ICMP in project trellis-control by opennetworkinglab.
the class IcmpHandlerTest method testPing4LocalGateway.
// Ping to a gateway attached to our leaf
@Test
public void testPing4LocalGateway() {
// Expected behavior
expect(segmentRoutingManager.deviceService.isAvailable(REMOTE_LEAF)).andReturn(true).times(1);
replay(segmentRoutingManager.deviceService);
// Process
icmpHandler.processIcmp(ETH_REQ_IPV4_LOCAL, CP12);
// Verify packet-out
Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV4_LOCAL.getSourceMAC());
assertNotNull(ethernet);
assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV4_LOCAL.getDestinationMAC()));
assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV4_LOCAL.getSourceMAC()));
assertTrue(ethernet.getPayload() instanceof IPv4);
IPv4 ip = (IPv4) ethernet.getPayload();
assertThat(ip.getSourceAddress(), is(DST_IPV4_LOCAL.toInt()));
assertThat(ip.getDestinationAddress(), is(SRC_IPV4_MY.toInt()));
assertTrue(ip.getPayload() instanceof ICMP);
ICMP icmp = (ICMP) ip.getPayload();
assertThat(icmp.getIcmpType(), is(TYPE_ECHO_REPLY));
assertThat(icmp.getIcmpCode(), is(CODE_ECHO_REPLY));
// Verify behavior
verify(segmentRoutingManager.deviceService);
}
Aggregations