use of net.floodlightcontroller.packet.IPacket in project open-kilda by telstra.
the class EthernetPacketToolboxTest method extractEthernetPayloadTest.
@Test
public void extractEthernetPayloadTest() {
short vlan1 = 1234;
short vlan2 = 2345;
short vlan3 = 4000;
byte[] originPayload = new byte[] { 0x55, (byte) 0xAA };
Ethernet ethernet = buildEthernet(new byte[] { // src mac address
0x01, // src mac address
0x0A, // src mac address
0x0A, // src mac address
0x0A, // src mac address
0x0A, // src mac address
0x0A, // dst mac address
0x01, // dst mac address
0x0B, // dst mac address
0x0B, // dst mac address
0x0B, // dst mac address
0x0B, // dst mac address
0x0B }, ethTypeToByteArray(EthType.Q_IN_Q), shortToByteArray(vlan1), ethTypeToByteArray(EthType.BRIDGING), shortToByteArray(vlan2), ethTypeToByteArray(EthType.VLAN_FRAME), shortToByteArray(vlan3), ethTypeToByteArray(EthType.IPv4), originPayload);
List<Integer> vlans = new ArrayList<>();
IPacket payload = EthernetPacketToolbox.extractPayload(ethernet, vlans);
assertEquals(3, vlans.size());
assertEquals(Integer.valueOf(vlan1), vlans.get(0));
assertEquals(Integer.valueOf(vlan2), vlans.get(1));
assertEquals(Integer.valueOf(vlan3), vlans.get(2));
assertArrayEquals(originPayload, payload.serialize());
}
use of net.floodlightcontroller.packet.IPacket 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));
}
use of net.floodlightcontroller.packet.IPacket in project open-kilda by telstra.
the class PingResponseCommandTest method success.
@Test
public void success() throws Exception {
final PingService realPingService = new PingService();
moduleContext.addService(PingService.class, realPingService);
final ISwitchManager realSwitchManager = new SwitchManager();
moduleContext.addService(ISwitchManager.class, realSwitchManager);
InputService inputService = createMock(InputService.class);
moduleContext.addService(InputService.class, inputService);
inputService.addTranslator(eq(OFType.PACKET_IN), anyObject());
replayAll();
final DatapathId dpIdBeta = DatapathId.of(0x0000fffe000002L);
final Ping ping = new Ping(new NetworkEndpoint(new SwitchId(dpIdBeta.getLong()), 8), new NetworkEndpoint(new SwitchId(dpId.getLong()), 9), new FlowTransitEncapsulation(2, FlowEncapsulationType.TRANSIT_VLAN), 3);
final PingData payload = PingData.of(ping);
moduleContext.addConfigParam(new PathVerificationService(), "hmac256-secret", "secret");
realPingService.setup(moduleContext);
byte[] signedPayload = realPingService.getSignature().sign(payload);
byte[] wireData = realPingService.wrapData(ping, signedPayload).serialize();
OFFactory ofFactory = new OFFactoryVer13();
OFPacketIn message = ofFactory.buildPacketIn().setReason(OFPacketInReason.ACTION).setXid(1L).setCookie(PingService.OF_CATCH_RULE_COOKIE).setData(wireData).build();
FloodlightContext metadata = new FloodlightContext();
IPacket decodedEthernet = new Ethernet().deserialize(wireData, 0, wireData.length);
Assert.assertTrue(decodedEthernet instanceof Ethernet);
IFloodlightProviderService.bcStore.put(metadata, IFloodlightProviderService.CONTEXT_PI_PAYLOAD, (Ethernet) decodedEthernet);
OfInput input = new OfInput(iofSwitch, message, metadata);
final PingResponseCommand command = makeCommand(input);
command.call();
final List<Message> replies = kafkaMessageCatcher.getValues();
Assert.assertEquals(1, replies.size());
InfoMessage response = (InfoMessage) replies.get(0);
PingResponse pingResponse = (PingResponse) response.getData();
Assert.assertNull(pingResponse.getError());
Assert.assertNotNull(pingResponse.getMeters());
Assert.assertEquals(payload.getPingId(), pingResponse.getPingId());
}
Aggregations