Search in sources :

Example 46 with MeterId

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));
}
Also used : FlowPath(org.openkilda.model.FlowPath) Path(org.openkilda.pce.Path) PathId(org.openkilda.model.PathId) FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) PathResources(org.openkilda.wfm.share.flow.resources.FlowResources.PathResources) SwitchId(org.openkilda.model.SwitchId) FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow) MeterId(org.openkilda.model.MeterId) Test(org.junit.Test)

Example 47 with MeterId

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));
}
Also used : OfMetadata(org.openkilda.rulemanager.OfMetadata) OFInstructionApplyActions(org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions) OFInstruction(org.projectfloodlight.openflow.protocol.instruction.OFInstruction) OFFactoryVer13(org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13) OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) OFAction(org.projectfloodlight.openflow.protocol.action.OFAction) Instructions(org.openkilda.rulemanager.Instructions) MeterId(org.openkilda.model.MeterId) Test(org.junit.Test)

Example 48 with MeterId

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);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) MessageContext(org.openkilda.messaging.MessageContext) OFMeterConfig(org.projectfloodlight.openflow.protocol.OFMeterConfig) MeterConfig(org.openkilda.model.MeterConfig) OFMeterConfig(org.projectfloodlight.openflow.protocol.OFMeterConfig) MeterId(org.openkilda.model.MeterId) Test(org.junit.Test) AbstractSpeakerCommandTest(org.openkilda.floodlight.command.AbstractSpeakerCommandTest)

Example 49 with MeterId

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);
    }
}
Also used : YFlowResources(org.openkilda.wfm.topology.flowhs.model.yflow.YFlowResources) SwitchId(org.openkilda.model.SwitchId) EndpointResources(org.openkilda.wfm.topology.flowhs.model.yflow.YFlowResources.EndpointResources) MeterId(org.openkilda.model.MeterId)

Example 50 with MeterId

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;
}
Also used : FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) Switch(org.openkilda.model.Switch) FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow) MeterId(org.openkilda.model.MeterId)

Aggregations

MeterId (org.openkilda.model.MeterId)62 PathId (org.openkilda.model.PathId)20 Flow (org.openkilda.model.Flow)19 FlowPath (org.openkilda.model.FlowPath)18 FlowSegmentCookie (org.openkilda.model.cookie.FlowSegmentCookie)18 Test (org.junit.Test)17 SwitchId (org.openkilda.model.SwitchId)16 Switch (org.openkilda.model.Switch)11 ArrayList (java.util.ArrayList)10 PathSegment (org.openkilda.model.PathSegment)9 MeterSpeakerData (org.openkilda.rulemanager.MeterSpeakerData)7 List (java.util.List)6 ValidateMetersResult (org.openkilda.wfm.topology.switchmanager.model.ValidateMetersResult)6 FlowMeter (org.openkilda.model.FlowMeter)5 MeterConfig (org.openkilda.model.MeterConfig)5 YFlow (org.openkilda.model.YFlow)5 Instructions (org.openkilda.rulemanager.Instructions)5 PortOutAction (org.openkilda.rulemanager.action.PortOutAction)5 ValidationService (org.openkilda.wfm.topology.switchmanager.service.ValidationService)5 MessageContext (org.openkilda.messaging.MessageContext)4