use of org.openkilda.floodlight.model.PingWiredView in project open-kilda by telstra.
the class PingServiceTest method testWrapUnwrapCycleVxlan.
@Test
public void testWrapUnwrapCycleVxlan() throws Exception {
Ping ping = new Ping(new NetworkEndpoint(new SwitchId(dpIdAlpha.getLong()), 8), new NetworkEndpoint(new SwitchId(dpIdBeta.getLong()), 9), new FlowTransitEncapsulation(2, FlowEncapsulationType.VXLAN), 3);
moduleContext.getServiceImpl(InputService.class).addTranslator(eq(OFType.PACKET_IN), anyObject(PingInputTranslator.class));
replayAll();
pingService.setup(moduleContext);
byte[] payload = new byte[] { 0x31, 0x32, 0x33, 0x34, 0x35 };
byte[] wrapped = pingService.wrapData(ping, payload).serialize();
IPacket ethernet = new Ethernet().deserialize(wrapped, 0, wrapped.length);
Assert.assertTrue(ethernet instanceof Ethernet);
IPacket ipv4 = ethernet.getPayload();
Assert.assertTrue(ipv4 instanceof IPv4);
IPacket udp = ipv4.getPayload();
Assert.assertTrue(udp instanceof UDP);
Assert.assertEquals(((UDP) udp).getSourcePort(), TransportPort.of(SwitchManager.STUB_VXLAN_UDP_SRC));
Assert.assertEquals(((UDP) udp).getDestinationPort(), TransportPort.of(SwitchManager.VXLAN_UDP_DST));
byte[] udpPayload = udp.getPayload().serialize();
Vxlan vxlan = (Vxlan) new Vxlan().deserialize(udpPayload, 0, udpPayload.length);
Assert.assertEquals((int) ping.getTransitEncapsulation().getId(), vxlan.getVni());
byte[] vxlanPayload = vxlan.getPayload().serialize();
IPacket decoded = new Ethernet().deserialize(vxlanPayload, 0, vxlanPayload.length);
Assert.assertTrue(decoded instanceof Ethernet);
PingWiredView parsed = pingService.unwrapData(dpIdBeta, (Ethernet) decoded);
Assert.assertNotNull(parsed);
Assert.assertArrayEquals(payload, parsed.getPayload());
Assert.assertTrue(parsed.getVlanStack().isEmpty());
}
use of org.openkilda.floodlight.model.PingWiredView in project open-kilda by telstra.
the class PingService method unwrapData.
/**
* Unpack network package.
* Verify all particular qualities used during discovery package creation time. Return packet payload.
*/
public PingWiredView unwrapData(DatapathId dpId, Ethernet packet) {
MacAddress targetL2Address = MacAddress.of(dpId);
if (!packet.getDestinationMACAddress().equals(targetL2Address)) {
return null;
}
List<Integer> vlanStack = new ArrayList<>();
IPacket payload = EthernetPacketToolbox.extractPayload(packet, vlanStack);
if (!(payload instanceof IPv4)) {
return null;
}
IPv4 ip = (IPv4) payload;
if (!NET_L3_ADDRESS.equals(ip.getSourceAddress().toString())) {
return null;
}
if (!NET_L3_ADDRESS.equals(ip.getDestinationAddress().toString())) {
return null;
}
if (!(ip.getPayload() instanceof UDP)) {
return null;
}
UDP udp = (UDP) ip.getPayload();
if (udp.getSourcePort().getPort() != NET_L3_PORT) {
return null;
}
if (udp.getDestinationPort().getPort() != NET_L3_PORT) {
return null;
}
return new PingWiredView(vlanStack, udp.getPayload().serialize());
}
use of org.openkilda.floodlight.model.PingWiredView in project open-kilda by telstra.
the class PingResponseCommand method unwrap.
private byte[] unwrap() {
if (input.packetInCookieMismatchAll(log, PingService.OF_CATCH_RULE_COOKIE, PingService.OF_CATCH_RULE_COOKIE_VXLAN)) {
return null;
}
Ethernet ethernetPackage = input.getPacketInPayload();
if (ethernetPackage == null) {
log.error("{} - payload is missing", input);
return null;
}
PingWiredView wiredView = getPingService().unwrapData(input.getDpId(), ethernetPackage);
if (wiredView == null) {
return null;
}
return wiredView.getPayload();
}
use of org.openkilda.floodlight.model.PingWiredView in project open-kilda by telstra.
the class PingServiceTest method testWrapUnwrapCycleVlan.
@Test
public void testWrapUnwrapCycleVlan() throws Exception {
Ping ping = new Ping(new NetworkEndpoint(new SwitchId(dpIdAlpha.getLong()), 8), new NetworkEndpoint(new SwitchId(dpIdBeta.getLong()), 9), new FlowTransitEncapsulation(2, FlowEncapsulationType.TRANSIT_VLAN), 3);
moduleContext.getServiceImpl(InputService.class).addTranslator(eq(OFType.PACKET_IN), anyObject(PingInputTranslator.class));
replayAll();
pingService.setup(moduleContext);
byte[] payload = new byte[] { 0x31, 0x32, 0x33, 0x34, 0x35 };
byte[] wrapped = pingService.wrapData(ping, payload).serialize();
IPacket decoded = new Ethernet().deserialize(wrapped, 0, wrapped.length);
Assert.assertTrue(decoded instanceof Ethernet);
PingWiredView parsed = pingService.unwrapData(dpIdBeta, (Ethernet) decoded);
Assert.assertNotNull(parsed);
Assert.assertArrayEquals(payload, parsed.getPayload());
Assert.assertEquals(ping.getTransitEncapsulation().getId(), parsed.getVlanStack().get(0));
}
Aggregations