use of org.openkilda.model.MeterId in project open-kilda by telstra.
the class FlowPathBuilderTest method shouldBuildFlowPathFor2SwitchPath.
@Test
public void shouldBuildFlowPathFor2SwitchPath() {
SwitchId switchId1 = new SwitchId(1);
SwitchId switchId2 = new SwitchId(2);
Path path = Path.builder().srcSwitchId(switchId1).destSwitchId(switchId2).segments(Collections.singletonList(Segment.builder().srcSwitchId(switchId1).srcPort(1).destSwitchId(switchId2).destPort(2).build())).build();
Flow flow = Flow.builder().flowId("test_flow").srcSwitch(Switch.builder().switchId(switchId1).build()).destSwitch(Switch.builder().switchId(switchId2).build()).build();
PathId pathId = new PathId("test_path_id");
MeterId meterId = new MeterId(MeterId.MIN_FLOW_METER_ID);
PathResources pathResources = PathResources.builder().pathId(pathId).meterId(meterId).build();
FlowSegmentCookie cookie = new FlowSegmentCookie(FlowPathDirection.FORWARD, 1);
FlowPath flowPath = builder.buildFlowPath(flow, pathResources, path, cookie, false, flow.getFlowId());
assertEquals(switchId1, flowPath.getSrcSwitchId());
assertEquals(switchId2, flowPath.getDestSwitchId());
assertEquals(pathId, flowPath.getPathId());
assertEquals(meterId, flowPath.getMeterId());
assertEquals(cookie, flowPath.getCookie());
assertThat(flowPath.getSegments(), hasSize(1));
}
use of org.openkilda.model.MeterId in project open-kilda by telstra.
the class OfInstructionsConverterTest method convertInstructionsTest.
@Test
public void convertInstructionsTest() {
OFFactory factory = new OFFactoryVer13();
Instructions instructions = Instructions.builder().goToTable(OfTable.PRE_INGRESS).goToMeter(new MeterId(2)).writeMetadata(new OfMetadata(123, 234)).applyActions(buildActions()).build();
List<OFInstruction> actual = OfInstructionsConverter.INSTANCE.convertInstructions(instructions, factory);
assertEquals(4, actual.size());
assertTrue(actual.contains(factory.instructions().gotoTable(TableId.of(1))));
assertTrue(actual.contains(factory.instructions().buildMeter().setMeterId(2).build()));
assertTrue(actual.contains(factory.instructions().buildWriteMetadata().setMetadata(U64.of(123)).setMetadataMask(U64.of(234)).build()));
OFInstructionApplyActions applyActionsInstruction = (OFInstructionApplyActions) actual.get(3);
assertEquals(12, applyActionsInstruction.getActions().size());
List<OFAction> expectedActions = buildActions(factory);
assertTrue(applyActionsInstruction.getActions().containsAll(expectedActions));
}
use of org.openkilda.model.MeterId in project open-kilda by telstra.
the class MeterVerifyCommandTest method shouldVerifyInaccurateMeterBandwidth.
@Test
public void shouldVerifyInaccurateMeterBandwidth() throws Exception {
MeterConfig validConfig = new MeterConfig(new MeterId(1), 100);
MeterVerifyCommand command1 = new MeterVerifyCommand(new MessageContext(), mapSwitchId(dpId), validConfig);
switchFeaturesSetup(sw, SwitchFeature.METERS, SwitchFeature.INACCURATE_METER);
SettableFuture<List<OFMeterConfigStatsReply>> statsReplyProxy = setupMeterConfigStatsReply();
// for command2
setupMeterConfigStatsReply();
replayAll();
CompletableFuture<MeterVerifyReport> result = command1.execute(commandProcessor);
// make one more command with altered config, to produce meter config flags/bands
MeterConfig invalidConfig = new MeterConfig(validConfig.getId(), validConfig.getBandwidth() + 1);
MeterVerifyCommand command2 = new MeterVerifyCommand(command1.getMessageContext(), command1.getSwitchId(), invalidConfig);
// must be executed, for let .setup() method to initialize all dependencies
command2.execute(commandProcessor);
OFMeterConfig reply = sw.getOFFactory().buildMeterConfig().setMeterId(validConfig.getId().getValue()).setFlags(command2.makeMeterFlags()).setEntries(command2.makeMeterBands()).build();
statsReplyProxy.set(wrapMeterStatsReply(reply));
verifySuccessCompletion(result);
}
use of org.openkilda.model.MeterId in project open-kilda by telstra.
the class DeallocateYFlowResourcesAction method perform.
@Override
public void perform(State from, State to, Event event, YFlowCreateContext context, YFlowCreateFsm stateMachine) {
String yFlowId = stateMachine.getYFlowId();
YFlowResources newResources = stateMachine.getNewResources();
if (newResources == null) {
log.debug("No resources were allocated for y-flow {}", yFlowId);
return;
}
notifyStats(stateMachine, newResources);
Optional<EndpointResources> sharedEndpointResources = ofNullable(newResources.getSharedEndpointResources());
Optional<MeterId> sharedEndpointMeterId = sharedEndpointResources.map(EndpointResources::getMeterId);
if (sharedEndpointMeterId.isPresent()) {
MeterId meterId = sharedEndpointMeterId.get();
SwitchId endpoint = sharedEndpointResources.get().getEndpoint();
resourcesManager.deallocateMeter(endpoint, meterId);
newResources.setSharedEndpointResources(null);
stateMachine.saveActionToHistory("The meter was deallocated", format("The meter %s / %s was deallocated", endpoint, meterId));
} else {
log.debug("No meter was allocated for y-flow {} (shared endpoint)", yFlowId);
}
Optional<EndpointResources> mainResources = ofNullable(newResources.getMainPathYPointResources());
Optional<MeterId> mainMeterId = mainResources.map(EndpointResources::getMeterId);
if (mainMeterId.isPresent()) {
MeterId meterId = mainMeterId.get();
SwitchId endpoint = mainResources.get().getEndpoint();
resourcesManager.deallocateMeter(endpoint, meterId);
newResources.setMainPathYPointResources(null);
stateMachine.saveActionToHistory("The meter was deallocated", format("The meter %s / %s was deallocated", endpoint, meterId));
} else {
log.debug("No meter was allocated for y-flow {} (main paths)", yFlowId);
}
Optional<EndpointResources> protectedResources = ofNullable(newResources.getProtectedPathYPointResources());
Optional<MeterId> protectedMeterId = protectedResources.map(EndpointResources::getMeterId);
if (protectedMeterId.isPresent()) {
MeterId meterId = protectedMeterId.get();
SwitchId endpoint = protectedResources.get().getEndpoint();
resourcesManager.deallocateMeter(endpoint, meterId);
newResources.setProtectedPathYPointResources(null);
stateMachine.saveActionToHistory("The meter was deallocated", format("The meter %s / %s was deallocated", endpoint, meterId));
} else {
log.debug("No meter was allocated for y-flow {} (protected paths)", yFlowId);
}
}
use of org.openkilda.model.MeterId in project open-kilda by telstra.
the class TestFlowBuilder method build.
/**
* Build a Flow with set properties.
*/
public Flow build() {
Switch srcSwitch = source.sw;
Switch destSwitch = destination.sw;
if (srcSwitch.getSwitchId().equals(destSwitch.getSwitchId())) {
checkArgument(transit.isEmpty(), "Transit endpoints were provided for a one-switch flow");
checkArgument(protectedTransit.isEmpty(), "ProtectedTransit endpoints were provided for a one-switch flow");
} else {
checkArgument(transit.isEmpty() || transit.size() % 2 == 0, "The number of transit endpoints is wrong");
}
checkArgument(protectedTransit.isEmpty() || protectedUnmaskedCookie != unmaskedCookie, "Same unmasked cookies provided with enabled ProtectedTransit");
Flow flow = Flow.builder().flowId(flowId).yFlowId(yFlowId).srcSwitch(srcSwitch).srcPort(source.port).srcVlan(srcVlan).destSwitch(destSwitch).destPort(destination.port).destVlan(destVlan).bandwidth(bandwidth).ignoreBandwidth(ignoreBandwidth).encapsulationType(encapsulationType).maxLatency(maxLatency).priority(priority).detectConnectedDevices(detectConnectedDevices).pathComputationStrategy(pathComputationStrategy).description(description).build();
flow.setStatus(status);
FlowPath forwardPath = buildFlowPath(flow, srcSwitch, destSwitch, transit, new FlowSegmentCookie(FlowPathDirection.FORWARD, unmaskedCookie), new MeterId(forwardMeterId));
flow.setForwardPath(forwardPath);
FlowPath reversePath = buildFlowPath(flow, destSwitch, srcSwitch, Lists.reverse(transit), new FlowSegmentCookie(FlowPathDirection.REVERSE, unmaskedCookie), new MeterId(reverseMeterId));
flow.setReversePath(reversePath);
if (!protectedTransit.isEmpty()) {
FlowPath protectedForwardPath = buildFlowPath(flow, srcSwitch, destSwitch, protectedTransit, new FlowSegmentCookie(FlowPathDirection.FORWARD, protectedUnmaskedCookie), new MeterId(protectedForwardMeterId));
flow.setProtectedForwardPath(protectedForwardPath);
FlowPath protectedReversePath = buildFlowPath(flow, destSwitch, srcSwitch, Lists.reverse(protectedTransit), new FlowSegmentCookie(FlowPathDirection.REVERSE, protectedUnmaskedCookie), new MeterId(protectedReverseMeterId));
flow.setProtectedReversePath(protectedReversePath);
}
return flow;
}
Aggregations