Search in sources :

Example 16 with FlowTransitEncapsulation

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

the class RecordHandler method doModifyGroupRequest.

private void doModifyGroupRequest(CommandMessage message) {
    SwitchId switchId = ((ModifyGroupRequest) message.getData()).getSwitchId();
    MirrorConfig mirrorConfig = ((ModifyGroupRequest) message.getData()).getMirrorConfig();
    FlowTransitEncapsulation encapsulation = ((ModifyGroupRequest) message.getData()).getEncapsulation();
    SwitchId egressSwitchId = ((ModifyGroupRequest) message.getData()).getEgressSwitchId();
    FlowTransitData flowTransitData = null;
    if (encapsulation != null) {
        flowTransitData = FlowTransitData.builder().ingressSwitchId(switchId).egressSwitchId(egressSwitchId).encapsulation(encapsulation).build();
    }
    logger.debug("Modify group '{}' for switch '{}'", mirrorConfig.getGroupId().intValue(), switchId);
    handleSpeakerCommand(new GroupModifyCommand(new MessageContext(message), switchId, mirrorConfig, flowTransitData));
    ModifyGroupResponse response = new ModifyGroupResponse(switchId, mirrorConfig.getGroupId().intValue());
    String correlationId = message.getCorrelationId();
    InfoMessage infoMessage = new InfoMessage(response, System.currentTimeMillis(), correlationId);
    getKafkaProducer().sendMessageAndTrack(context.getKafkaSwitchManagerTopic(), correlationId, infoMessage);
}
Also used : FlowTransitData(org.openkilda.floodlight.model.FlowTransitData) MirrorConfig(org.openkilda.model.MirrorConfig) InfoMessage(org.openkilda.messaging.info.InfoMessage) ModifyGroupResponse(org.openkilda.messaging.info.switches.ModifyGroupResponse) FlowTransitEncapsulation(org.openkilda.model.FlowTransitEncapsulation) SwitchId(org.openkilda.model.SwitchId) MessageContext(org.openkilda.messaging.MessageContext) GroupModifyCommand(org.openkilda.floodlight.command.group.GroupModifyCommand) ModifyGroupRequest(org.openkilda.messaging.command.switches.ModifyGroupRequest)

Example 17 with FlowTransitEncapsulation

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

the class PersistenceDataAdapterTest method shouldProvideCorrectVlanEncapsulation.

@Test
public void shouldProvideCorrectVlanEncapsulation() {
    PathId pathId = new PathId("path1");
    Set<PathId> pathIds = Sets.newHashSet(pathId);
    TransitVlan transitVlan = TransitVlan.builder().flowId("flowId").pathId(pathId).vlan(8).build();
    when(transitVlanRepository.findByPathId(pathId, null)).thenReturn(Collections.singletonList(transitVlan));
    adapter = PersistenceDataAdapter.builder().pathIds(pathIds).persistenceManager(persistenceManager).build();
    FlowTransitEncapsulation actual = adapter.getTransitEncapsulation(pathId, null);
    assertEquals(FlowEncapsulationType.TRANSIT_VLAN, actual.getType());
    assertEquals(transitVlan.getVlan(), actual.getId().intValue());
    adapter.getTransitEncapsulation(pathId, null);
    verify(transitVlanRepository).findByPathId(pathId, null);
    verifyNoMoreInteractions(transitVlanRepository);
    verifyNoInteractions(vxlanRepository);
}
Also used : PathId(org.openkilda.model.PathId) TransitVlan(org.openkilda.model.TransitVlan) FlowTransitEncapsulation(org.openkilda.model.FlowTransitEncapsulation) Test(org.junit.Test)

Example 18 with FlowTransitEncapsulation

use of org.openkilda.model.FlowTransitEncapsulation 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 19 with FlowTransitEncapsulation

use of org.openkilda.model.FlowTransitEncapsulation 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 20 with FlowTransitEncapsulation

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

the class RuleManagerImpl method buildFlowRulesForSwitch.

/**
 * Builds command data only for switches present in the map. Silently skips all others.
 */
private List<SpeakerData> buildFlowRulesForSwitch(SwitchId switchId, FlowPath flowPath, DataAdapter adapter) {
    List<SpeakerData> result = new ArrayList<>();
    Flow flow = adapter.getFlow(flowPath.getPathId());
    Switch sw = adapter.getSwitch(switchId);
    PathId oppositePathId = flow.getOppositePathId(flowPath.getPathId()).orElse(null);
    FlowTransitEncapsulation encapsulation = adapter.getTransitEncapsulation(flowPath.getPathId(), oppositePathId);
    if (switchId.equals(flowPath.getSrcSwitchId()) && !flow.isProtectedPath(flowPath.getPathId())) {
        // TODO filter out equal shared rules from the result list
        result.addAll(buildIngressCommands(sw, flowPath, flow, encapsulation, new HashSet<>(), adapter.getSwitchProperties(switchId), adapter.getFeatureToggles()));
    }
    if (!flowPath.isOneSwitchFlow()) {
        if (switchId.equals(flowPath.getDestSwitchId())) {
            result.addAll(buildEgressCommands(sw, flowPath, flow, encapsulation));
        }
        for (int i = 1; i < flowPath.getSegments().size(); i++) {
            PathSegment firstSegment = flowPath.getSegments().get(i - 1);
            PathSegment secondSegment = flowPath.getSegments().get(i);
            if (switchId.equals(firstSegment.getDestSwitchId()) && switchId.equals(secondSegment.getSrcSwitchId())) {
                result.addAll(buildTransitCommands(sw, flowPath, encapsulation, firstSegment, secondSegment));
                break;
            }
        }
        if (flow.isLooped() && sw.getSwitchId().equals(flow.getLoopSwitchId()) && !flow.isProtectedPath(flowPath.getPathId())) {
            result.addAll(buildTransitLoopCommands(sw, flowPath, flow, encapsulation));
        }
    }
    return result;
}
Also used : PathId(org.openkilda.model.PathId) Switch(org.openkilda.model.Switch) ArrayList(java.util.ArrayList) FlowTransitEncapsulation(org.openkilda.model.FlowTransitEncapsulation) PathSegment(org.openkilda.model.PathSegment) FlowEndpoint(org.openkilda.model.FlowEndpoint) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) HashSet(java.util.HashSet)

Aggregations

FlowTransitEncapsulation (org.openkilda.model.FlowTransitEncapsulation)21 SwitchId (org.openkilda.model.SwitchId)12 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)7 Flow (org.openkilda.model.Flow)7 YFlow (org.openkilda.model.YFlow)6 InfoMessage (org.openkilda.messaging.info.InfoMessage)5 NetworkEndpoint (org.openkilda.messaging.model.NetworkEndpoint)5 Ping (org.openkilda.messaging.model.Ping)5 PathId (org.openkilda.model.PathId)5 Switch (org.openkilda.model.Switch)5 Ethernet (net.floodlightcontroller.packet.Ethernet)3 IPacket (net.floodlightcontroller.packet.IPacket)3 FlowEndpoint (org.openkilda.model.FlowEndpoint)3 PathSegment (org.openkilda.model.PathSegment)3 HashSet (java.util.HashSet)2 EgressFlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.EgressFlowSegmentRequestFactory)2 FlowTransitData (org.openkilda.floodlight.model.FlowTransitData)2 InputService (org.openkilda.floodlight.service.of.InputService)2 MessageContext (org.openkilda.messaging.MessageContext)2