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);
}
}
}
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);
}
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()));
}
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);
}
}
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);
}
Aggregations