use of org.openkilda.floodlight.shared.packet.Vxlan 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.shared.packet.Vxlan in project open-kilda by telstra.
the class PingService method wrapData.
/**
* Wrap ping data into L2, l3 and L4 network packages.
*/
public IPacket wrapData(Ping ping, byte[] payload) throws PingImpossibleException {
Data l7 = new Data(payload);
UDP l4 = new UDP();
l4.setPayload(l7);
l4.setSourcePort(TransportPort.of(NET_L3_PORT));
l4.setDestinationPort(TransportPort.of(NET_L3_PORT));
IPv4 l3 = new IPv4();
l3.setPayload(l4);
l3.setSourceAddress(NET_L3_ADDRESS);
l3.setDestinationAddress(NET_L3_ADDRESS);
l3.setTtl(NET_L3_TTL);
Ethernet l2 = new Ethernet();
l2.setPayload(l3);
l2.setEtherType(EthType.IPv4);
l2.setSourceMACAddress(magicSourceMacAddress);
DatapathId egressSwitch = DatapathId.of(ping.getDest().getDatapath().toLong());
l2.setDestinationMACAddress(MacAddress.of(egressSwitch));
if (FlowEncapsulationType.TRANSIT_VLAN.equals(ping.getTransitEncapsulation().getType())) {
l2.setVlanID(ping.getTransitEncapsulation().getId().shortValue());
return l2;
} else if (FlowEncapsulationType.VXLAN.equals(ping.getTransitEncapsulation().getType())) {
Vxlan vxlan = new Vxlan();
vxlan.setPayload(l2);
vxlan.setVni(ping.getTransitEncapsulation().getId());
UDP udp = new UDP();
udp.setPayload(vxlan);
udp.setSourcePort(TransportPort.of(SwitchManager.STUB_VXLAN_UDP_SRC));
udp.setDestinationPort(TransportPort.of(SwitchManager.VXLAN_UDP_DST));
IPv4 ipv4 = new IPv4();
ipv4.setPayload(udp);
ipv4.setProtocol(IpProtocol.UDP);
ipv4.setSourceAddress(SwitchManager.STUB_VXLAN_IPV4_SRC);
ipv4.setDestinationAddress(SwitchManager.STUB_VXLAN_IPV4_DST);
ipv4.setTtl(NET_L3_TTL);
Ethernet ethernet = new Ethernet();
ethernet.setPayload(ipv4);
ethernet.setEtherType(EthType.IPv4);
ethernet.setSourceMACAddress(magicSourceMacAddress);
ethernet.setDestinationMACAddress(MacAddress.of(egressSwitch));
return ethernet;
}
throw new PingImpossibleException(ping, Errors.INCORRECT_REQUEST);
}
Aggregations