Search in sources :

Example 26 with SwitchId

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

the class FlowValidator method validateFlowLoop.

private void validateFlowLoop(RequestedFlow requestedFlow) throws InvalidFlowException {
    if (requestedFlow.getLoopSwitchId() != null) {
        SwitchId loopSwitchId = requestedFlow.getLoopSwitchId();
        boolean loopSwitchIsTerminating = requestedFlow.getSrcSwitch().equals(loopSwitchId) || requestedFlow.getDestSwitch().equals(loopSwitchId);
        if (!loopSwitchIsTerminating) {
            throw new InvalidFlowException("Loop switch is not terminating in flow path", ErrorType.PARAMETERS_INVALID);
        }
    }
}
Also used : SwitchId(org.openkilda.model.SwitchId)

Example 27 with SwitchId

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

the class FlowValidator method flowMirrorPointValidate.

/**
 * Validate the flow mirror point.
 */
public void flowMirrorPointValidate(RequestedFlowMirrorPoint mirrorPoint) throws InvalidFlowException, UnavailableFlowEndpointException {
    checkSwitchesExistsAndActive(mirrorPoint.getMirrorPointSwitchId(), mirrorPoint.getSinkEndpoint().getSwitchId());
    EndpointDescriptor descriptor = EndpointDescriptor.makeDestination(FlowEndpoint.builder().switchId(mirrorPoint.getSinkEndpoint().getSwitchId()).portNumber(mirrorPoint.getSinkEndpoint().getPortNumber()).outerVlanId(mirrorPoint.getSinkEndpoint().getOuterVlanId()).innerVlanId(mirrorPoint.getSinkEndpoint().getInnerVlanId()).build());
    SwitchId switchId = descriptor.endpoint.getSwitchId();
    SwitchProperties properties = switchPropertiesRepository.findBySwitchId(switchId).orElseThrow(() -> new InvalidFlowException(format("Couldn't get switch properties for %s switch %s.", descriptor.name, switchId), ErrorType.DATA_INVALID));
    checkForConnectedDevisesConflict(mirrorPoint.getFlowId(), mirrorPoint.getMirrorPointSwitchId());
    checkForMultiTableRequirement(descriptor, properties);
    checkFlowForIslConflicts(descriptor);
    checkFlowForFlowConflicts(mirrorPoint.getMirrorPointId(), descriptor);
    checkFlowForSinkEndpointConflicts(descriptor);
    checkFlowForServer42Conflicts(descriptor, properties);
}
Also used : SwitchId(org.openkilda.model.SwitchId) SwitchProperties(org.openkilda.model.SwitchProperties)

Example 28 with SwitchId

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

the class BaseResourceAllocationActionTest method updateAvailableBandwidthFailsOnOverProvisionTest.

@Test(expected = ResourceAllocationException.class)
public void updateAvailableBandwidthFailsOnOverProvisionTest() throws ResourceAllocationException {
    islRepositorySpy = spy(persistenceManager.getRepositoryFactory().createIslRepository());
    when(repositoryFactory.createIslRepository()).thenReturn(islRepositorySpy);
    doReturn(-1L).when(islRepositorySpy).updateAvailableBandwidth(any(), anyInt(), any(), anyInt());
    BaseResourceAllocationAction action = mock(BaseResourceAllocationAction.class, Mockito.withSettings().useConstructor(persistenceManager, 3, 3, 3, pathComputer, resourcesManager, dashboardLogger).defaultAnswer(Mockito.CALLS_REAL_METHODS));
    PathSegment segment = PathSegment.builder().pathId(new PathId("")).srcSwitch(Switch.builder().switchId(new SwitchId(1)).build()).srcPort(1).destSwitch(Switch.builder().switchId(new SwitchId(2)).build()).destPort(2).build();
    action.createPathSegments(singletonList(segment), Suppliers.ofInstance(emptyMap()));
}
Also used : PathId(org.openkilda.model.PathId) SwitchId(org.openkilda.model.SwitchId) PathSegment(org.openkilda.model.PathSegment) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 29 with SwitchId

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

the class FlowValidationHubServiceTest method testMainPath.

@Test
public void testMainPath() throws DuplicateKeyException, UnknownKeyException {
    FlowValidationHubCarrier carrier = new FlowValidationHubCarrier() {

        @Override
        public void sendSpeakerRequest(String flowId, CommandData commandData) {
            assertTrue(commandData instanceof DumpRulesForFlowHsRequest || commandData instanceof DumpMetersForFlowHsRequest || commandData instanceof DumpGroupsForFlowHsRequest);
            List<SwitchId> switchIds = Lists.newArrayList(TEST_SWITCH_ID_A, TEST_SWITCH_ID_B, TEST_SWITCH_ID_C, TEST_SWITCH_ID_E);
            if (commandData instanceof DumpRulesForFlowHsRequest) {
                assertTrue(switchIds.contains(((DumpRulesForFlowHsRequest) commandData).getSwitchId()));
            } else if (commandData instanceof DumpMetersForFlowHsRequest) {
                assertTrue(switchIds.contains(((DumpMetersForFlowHsRequest) commandData).getSwitchId()));
            } else {
                assertTrue(switchIds.contains(((DumpGroupsForFlowHsRequest) commandData).getSwitchId()));
            }
        }

        @Override
        public void sendNorthboundResponse(List<? extends InfoData> message) {
            assertEquals(4, message.size());
            try {
                assertEquals(flowValidationService.validateFlow(TEST_FLOW_ID_A, getSwitchFlowEntriesWithTransitVlan(), getSwitchMeterEntries(), getSwitchGroupEntries()), message);
            } catch (FlowNotFoundException | SwitchNotFoundException e) {
            // tested in the FlowValidationServiceTest
            }
        }

        @Override
        public void sendNorthboundResponse(Message message) {
            fail();
        }

        @Override
        public void cancelTimeoutCallback(String key) {
            assertEquals(TEST_KEY, key);
        }

        @Override
        public void sendInactive() {
        }
    };
    flowValidationHubService = new FlowValidationHubService(carrier, persistenceManager, flowResourcesManager, MIN_BURST_SIZE_IN_KBITS, BURST_COEFFICIENT);
    buildTransitVlanFlow("");
    flowValidationHubService.handleFlowValidationRequest(TEST_KEY, new CommandContext(), new FlowValidationRequest(TEST_FLOW_ID_A));
    for (SwitchFlowEntries switchFlowEntries : getSwitchFlowEntriesWithTransitVlan()) {
        flowValidationHubService.handleAsyncResponse(TEST_KEY, switchFlowEntries);
    }
    for (SwitchMeterEntries switchMeterEntries : getSwitchMeterEntries()) {
        flowValidationHubService.handleAsyncResponse(TEST_KEY, switchMeterEntries);
    }
    for (SwitchGroupEntries switchGroupEntries : getSwitchGroupEntries()) {
        flowValidationHubService.handleAsyncResponse(TEST_KEY, switchGroupEntries);
    }
}
Also used : DumpGroupsForFlowHsRequest(org.openkilda.messaging.command.switches.DumpGroupsForFlowHsRequest) FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) SwitchFlowEntries(org.openkilda.messaging.info.rule.SwitchFlowEntries) Message(org.openkilda.messaging.Message) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) CommandContext(org.openkilda.wfm.CommandContext) SwitchMeterEntries(org.openkilda.messaging.info.meter.SwitchMeterEntries) SwitchId(org.openkilda.model.SwitchId) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException) DumpMetersForFlowHsRequest(org.openkilda.messaging.command.switches.DumpMetersForFlowHsRequest) FlowValidationRequest(org.openkilda.messaging.command.flow.FlowValidationRequest) InfoData(org.openkilda.messaging.info.InfoData) DumpRulesForFlowHsRequest(org.openkilda.messaging.command.switches.DumpRulesForFlowHsRequest) SwitchGroupEntries(org.openkilda.messaging.info.rule.SwitchGroupEntries) List(java.util.List) CommandData(org.openkilda.messaging.command.CommandData) Test(org.junit.Test)

Example 30 with SwitchId

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

the class YFlowValidationHubServiceTest method shouldValidateYFlowSuccessfully.

@Test
public void shouldValidateYFlowSuccessfully() throws DuplicateKeyException {
    // given
    String yFlowId = "test_y_flow_1";
    YFlow yFlow = createYFlowViaTransit(yFlowId);
    YFlowSwitchFlowEntriesBuilder flowEntriesBuilder = new YFlowSwitchFlowEntriesBuilder(yFlow, persistenceManager.getRepositoryFactory().createTransitVlanRepository(), persistenceManager.getRepositoryFactory().createVxlanRepository());
    Map<SwitchId, Collection<FlowEntry>> flowEntries = flowEntriesBuilder.getFlowEntries();
    Map<SwitchId, Collection<MeterEntry>> meterEntries = flowEntriesBuilder.getMeterEntries();
    Map<SwitchId, Collection<GroupEntry>> groupEntries = flowEntriesBuilder.getGroupEntries();
    YFlowValidationHubService service = makeYFlowValidationHubService();
    service.handleRequest(yFlow.getYFlowId(), new CommandContext(), yFlow.getYFlowId());
    // when
    handleSpeakerRequests(service, yFlowId, flowEntries, meterEntries, groupEntries);
    // then
    verifyNorthboundSuccessResponse(yFlowValidationHubCarrier);
}
Also used : YFlow(org.openkilda.model.YFlow) CommandContext(org.openkilda.wfm.CommandContext) Collection(java.util.Collection) YFlowSwitchFlowEntriesBuilder(org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowSwitchFlowEntriesBuilder) SwitchId(org.openkilda.model.SwitchId) Test(org.junit.Test) AbstractYFlowTest(org.openkilda.wfm.topology.flowhs.service.AbstractYFlowTest)

Aggregations

SwitchId (org.openkilda.model.SwitchId)339 Test (org.junit.Test)149 Flow (org.openkilda.model.Flow)73 Switch (org.openkilda.model.Switch)69 List (java.util.List)59 FlowPath (org.openkilda.model.FlowPath)49 ArrayList (java.util.ArrayList)44 Collectors (java.util.stream.Collectors)37 PathId (org.openkilda.model.PathId)36 PathComputer (org.openkilda.pce.PathComputer)35 Set (java.util.Set)34 YFlow (org.openkilda.model.YFlow)33 Map (java.util.Map)30 GetPathsResult (org.openkilda.pce.GetPathsResult)30 InfoMessage (org.openkilda.messaging.info.InfoMessage)29 String.format (java.lang.String.format)28 HashSet (java.util.HashSet)27 Optional (java.util.Optional)27 Collection (java.util.Collection)26 Collections (java.util.Collections)26