use of net.floodlightcontroller.packet.IPacket in project open-kilda by telstra.
the class EthernetPacketToolbox method extractPayload.
/**
* Read through intermediate vlan headers up to actual packet payload. Return both payload and vlan stack.
*/
public static IPacket extractPayload(Ethernet packet, List<Integer> vlanStack) {
short rootVlan = packet.getVlanID();
if (0 < rootVlan) {
vlanStack.add((int) rootVlan);
}
IPacket payload = packet.getPayload();
while (payload instanceof VlanTag) {
short vlanId = ((VlanTag) payload).getVlanId();
vlanStack.add((int) vlanId);
payload = payload.getPayload();
}
return payload;
}
use of net.floodlightcontroller.packet.IPacket in project open-kilda by telstra.
the class ConnectedDevicesService method deserializeArp.
@VisibleForTesting
ArpPacketData deserializeArp(Ethernet eth, SwitchId switchId, long cookie) {
try {
List<Integer> vlans = new ArrayList<>();
IPacket payload = EthernetPacketToolbox.extractPayload(eth, vlans);
if (payload instanceof ARP) {
return new ArpPacketData((ARP) payload, vlans);
}
} catch (Exception exception) {
logger.info("Could not deserialize ARP packet {} on switch {}. Cookie {}. Deserialization failure: {}", eth, switchId, Cookie.toString(cookie), exception.getMessage(), exception);
return null;
}
logger.info("Got invalid ARP packet: {} on switch {}. Cookie {}", eth, switchId, cookie);
return null;
}
use of net.floodlightcontroller.packet.IPacket in project open-kilda by telstra.
the class ConnectedDevicesService method deserializeLldp.
@VisibleForTesting
LldpPacketData deserializeLldp(Ethernet eth, SwitchId switchId, long cookie) {
try {
List<Integer> vlans = new ArrayList<>();
IPacket payload = EthernetPacketToolbox.extractPayload(eth, vlans);
if (payload instanceof LLDP) {
LldpPacket lldpPacket = new LldpPacket((LLDP) payload);
return new LldpPacketData(lldpPacket, vlans);
}
} catch (Exception exception) {
logger.info("Could not deserialize LLDP packet {} on switch {}. Cookie {}. Deserialization failure: {}", eth, switchId, Cookie.toString(cookie), exception.getMessage(), exception);
return null;
}
logger.info("Got invalid lldp packet: {} on switch {}. Cookie {}", eth, switchId, cookie);
return null;
}
use of net.floodlightcontroller.packet.IPacket 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 net.floodlightcontroller.packet.IPacket 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());
}
Aggregations