Search in sources :

Example 6 with Ping

use of org.openkilda.messaging.model.Ping 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));
}
Also used : IPacket(net.floodlightcontroller.packet.IPacket) InputService(org.openkilda.floodlight.service.of.InputService) NetworkEndpoint(org.openkilda.messaging.model.NetworkEndpoint) PingWiredView(org.openkilda.floodlight.model.PingWiredView) Ping(org.openkilda.messaging.model.Ping) Ethernet(net.floodlightcontroller.packet.Ethernet) FlowTransitEncapsulation(org.openkilda.model.FlowTransitEncapsulation) SwitchId(org.openkilda.model.SwitchId) Test(org.junit.Test)

Example 7 with Ping

use of org.openkilda.messaging.model.Ping 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());
}
Also used : OfInput(org.openkilda.floodlight.model.OfInput) IPacket(net.floodlightcontroller.packet.IPacket) ISwitchManager(org.openkilda.floodlight.switchmanager.ISwitchManager) NetworkEndpoint(org.openkilda.messaging.model.NetworkEndpoint) InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) OFMessage(org.projectfloodlight.openflow.protocol.OFMessage) OFFactoryVer13(org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13) OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) FlowTransitEncapsulation(org.openkilda.model.FlowTransitEncapsulation) DatapathId(org.projectfloodlight.openflow.types.DatapathId) SwitchId(org.openkilda.model.SwitchId) PingResponse(org.openkilda.messaging.floodlight.response.PingResponse) SwitchManager(org.openkilda.floodlight.switchmanager.SwitchManager) ISwitchManager(org.openkilda.floodlight.switchmanager.ISwitchManager) PingData(org.openkilda.floodlight.model.PingData) InputService(org.openkilda.floodlight.service.of.InputService) PathVerificationService(org.openkilda.floodlight.pathverification.PathVerificationService) InfoMessage(org.openkilda.messaging.info.InfoMessage) PingService(org.openkilda.floodlight.service.ping.PingService) Ping(org.openkilda.messaging.model.Ping) Ethernet(net.floodlightcontroller.packet.Ethernet) OFPacketIn(org.projectfloodlight.openflow.protocol.OFPacketIn) FloodlightContext(net.floodlightcontroller.core.FloodlightContext) Test(org.junit.Test)

Example 8 with Ping

use of org.openkilda.messaging.model.Ping in project open-kilda by telstra.

the class PingProducer method buildPing.

private Ping buildPing(PingContext pingContext, FlowDirection direction) {
    Flow flow = pingContext.getFlow();
    FlowEndpoint ingress;
    FlowEndpoint egress;
    int islPort;
    if (FlowDirection.FORWARD == direction) {
        ingress = new FlowSourceAdapter(flow).getEndpoint();
        egress = new FlowDestAdapter(flow).getEndpoint();
        islPort = getIslPort(flow, flow.getForwardPath());
    } else if (FlowDirection.REVERSE == direction) {
        ingress = new FlowDestAdapter(flow).getEndpoint();
        egress = new FlowSourceAdapter(flow).getEndpoint();
        islPort = getIslPort(flow, flow.getReversePath());
    } else {
        throw new IllegalArgumentException(String.format("Unexpected %s value: %s", FlowDirection.class.getCanonicalName(), direction));
    }
    return new Ping(new NetworkEndpoint(ingress.getSwitchId(), ingress.getPortNumber()), new NetworkEndpoint(egress.getSwitchId(), egress.getPortNumber()), pingContext.getTransitEncapsulation(), islPort);
}
Also used : FlowSourceAdapter(org.openkilda.adapter.FlowSourceAdapter) FlowEndpoint(org.openkilda.model.FlowEndpoint) NetworkEndpoint(org.openkilda.messaging.model.NetworkEndpoint) FlowDirection(org.openkilda.messaging.model.FlowDirection) FlowDestAdapter(org.openkilda.adapter.FlowDestAdapter) Ping(org.openkilda.messaging.model.Ping) FlowEndpoint(org.openkilda.model.FlowEndpoint) NetworkEndpoint(org.openkilda.messaging.model.NetworkEndpoint) Flow(org.openkilda.model.Flow)

Example 9 with Ping

use of org.openkilda.messaging.model.Ping in project open-kilda by telstra.

the class PingRequestTest method serializeLoop.

@Test
public void serializeLoop() throws Exception {
    Ping ping = new Ping((short) 100, new NetworkEndpoint(new SwitchId("ff:fe:00:00:00:00:00:01"), 8), new NetworkEndpoint(new SwitchId("ff:fe:00:00:00:00:00:02"), 10));
    PingRequest origin = new PingRequest(ping);
    CommandMessage wrapper = new CommandMessage(origin, System.currentTimeMillis(), getClass().getSimpleName());
    serializer.serialize(wrapper);
    CommandMessage decodedWrapper = (CommandMessage) serializer.deserialize();
    CommandData decoded = decodedWrapper.getData();
    Assert.assertEquals(String.format("%s object have been mangled in serialisation/deserialization loop", origin.getClass().getName()), origin, decoded);
}
Also used : NetworkEndpoint(org.openkilda.messaging.model.NetworkEndpoint) Ping(org.openkilda.messaging.model.Ping) SwitchId(org.openkilda.model.SwitchId) CommandData(org.openkilda.messaging.command.CommandData) CommandMessage(org.openkilda.messaging.command.CommandMessage) Test(org.junit.Test)

Aggregations

Ping (org.openkilda.messaging.model.Ping)9 Test (org.junit.Test)7 NetworkEndpoint (org.openkilda.messaging.model.NetworkEndpoint)7 SwitchId (org.openkilda.model.SwitchId)6 FlowTransitEncapsulation (org.openkilda.model.FlowTransitEncapsulation)5 Ethernet (net.floodlightcontroller.packet.Ethernet)3 IPacket (net.floodlightcontroller.packet.IPacket)3 InputService (org.openkilda.floodlight.service.of.InputService)3 InfoMessage (org.openkilda.messaging.info.InfoMessage)3 PingWiredView (org.openkilda.floodlight.model.PingWiredView)2 InfoData (org.openkilda.messaging.info.InfoData)2 PingMeters (org.openkilda.messaging.model.PingMeters)2 OFMessage (org.projectfloodlight.openflow.protocol.OFMessage)2 OFFactoryVer13 (org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13)2 DatapathId (org.projectfloodlight.openflow.types.DatapathId)2 FloodlightContext (net.floodlightcontroller.core.FloodlightContext)1 IOFSwitch (net.floodlightcontroller.core.IOFSwitch)1 IPv4 (net.floodlightcontroller.packet.IPv4)1 UDP (net.floodlightcontroller.packet.UDP)1 Values (org.apache.storm.tuple.Values)1