Search in sources :

Example 21 with MeterId

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

the class RuleManagerImpl method buildTransitYFlowCommands.

private List<SpeakerData> buildTransitYFlowCommands(FlowPath flowPath, FlowPath altFlowPath, DataAdapter adapter) {
    Flow flow = adapter.getFlow(flowPath.getPathId());
    Flow altFlow = adapter.getFlow(altFlowPath.getPathId());
    YFlow yFlow = adapter.getYFlow(flowPath.getPathId());
    if (yFlow == null) {
        return Collections.emptyList();
    }
    SwitchId sharedSwitchId = yFlow.getSharedEndpoint().getSwitchId();
    if (sharedSwitchId.equals(flowPath.getSrcSwitchId()) || sharedSwitchId.equals(altFlowPath.getSrcSwitchId())) {
        return Collections.emptyList();
    }
    SwitchId yPointSwitchId = yFlow.getYPoint();
    MeterId yPointMeterId = yFlow.getMeterId();
    if (flow.isProtectedPath(flowPath.getPathId()) && altFlow.isProtectedPath(altFlowPath.getPathId())) {
        yPointSwitchId = yFlow.getProtectedPathYPoint();
        yPointMeterId = yFlow.getProtectedPathMeterId();
    }
    Switch yPointSwitch = adapter.getSwitch(yPointSwitchId);
    if (yPointSwitch == null) {
        return Collections.emptyList();
    }
    FlowTransitEncapsulation encapsulation = getFlowTransitEncapsulation(flowPath.getPathId(), flow, adapter);
    FlowTransitEncapsulation altEncapsulation = getFlowTransitEncapsulation(altFlowPath.getPathId(), altFlow, adapter);
    SwitchPathSegments switchPathSegments = findPathSegmentsForSwitch(yPointSwitchId, flowPath.getSegments());
    SwitchPathSegments altSwitchPathSegments = findPathSegmentsForSwitch(yPointSwitchId, altFlowPath.getSegments());
    if (switchPathSegments == null || altSwitchPathSegments == null) {
        return Collections.emptyList();
    }
    RuleGenerator generator = flowRulesFactory.getTransitYRuleGenerator(flowPath, encapsulation, switchPathSegments.getFirstPathSegment(), switchPathSegments.getSecondPathSegment(), altFlowPath, altEncapsulation, altSwitchPathSegments.getFirstPathSegment(), altSwitchPathSegments.getSecondPathSegment(), yPointMeterId);
    return generator.generateCommands(yPointSwitch);
}
Also used : YFlow(org.openkilda.model.YFlow) Switch(org.openkilda.model.Switch) FlowTransitEncapsulation(org.openkilda.model.FlowTransitEncapsulation) SwitchId(org.openkilda.model.SwitchId) RuleGenerator(org.openkilda.rulemanager.factory.RuleGenerator) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) MeterId(org.openkilda.model.MeterId)

Example 22 with MeterId

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

the class ValidationServiceImplTest method validateMetersProperMetersESwitch.

@Test
public void validateMetersProperMetersESwitch() {
    ValidationService validationService = new ValidationServiceImpl(persistenceManager().build());
    long rateESwitch = FLOW_E_BANDWIDTH + (long) (FLOW_E_BANDWIDTH * 0.01) - 1;
    long burstSize = (long) (FLOW_E_BANDWIDTH * 1.05);
    long burstSizeESwitch = burstSize + (long) (burstSize * 0.01) - 1;
    MeterSpeakerData meter = MeterSpeakerData.builder().meterId(new MeterId(32)).rate(rateESwitch).burst(burstSizeESwitch).ofVersion(OfVersion.OF_13).flags(Sets.newHashSet(MeterFlag.KBPS, MeterFlag.BURST, MeterFlag.STATS)).build();
    ValidateMetersResult response = validationService.validateMeters(SWITCH_ID_E, singletonList(meter), singletonList(meter));
    assertTrue(response.getMissingMeters().isEmpty());
    assertTrue(response.getMisconfiguredMeters().isEmpty());
    assertFalse(response.getProperMeters().isEmpty());
    assertEquals(32L, (long) response.getProperMeters().get(0).getMeterId());
    assertMeter(response.getProperMeters().get(0), 32, rateESwitch, burstSizeESwitch, new String[] { "KBPS", "BURST", "STATS" });
    assertTrue(response.getExcessMeters().isEmpty());
}
Also used : MeterSpeakerData(org.openkilda.rulemanager.MeterSpeakerData) ValidateMetersResult(org.openkilda.wfm.topology.switchmanager.model.ValidateMetersResult) ValidationService(org.openkilda.wfm.topology.switchmanager.service.ValidationService) MeterId(org.openkilda.model.MeterId) Test(org.junit.Test)

Example 23 with MeterId

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

the class ValidationServiceImplTest method validateMetersMissingAndExcessMeters.

@Test
public void validateMetersMissingAndExcessMeters() {
    ValidationService validationService = new ValidationServiceImpl(persistenceManager().build());
    MeterSpeakerData actualMeter = MeterSpeakerData.builder().meterId(new MeterId(33)).rate(10000).burst(10500).ofVersion(OfVersion.OF_13).flags(Sets.newHashSet(MeterFlag.KBPS, MeterFlag.BURST, MeterFlag.STATS)).build();
    MeterSpeakerData expectedMeter = MeterSpeakerData.builder().meterId(new MeterId(32)).rate(10000).burst(10500).ofVersion(OfVersion.OF_13).flags(Sets.newHashSet(MeterFlag.KBPS, MeterFlag.BURST, MeterFlag.STATS)).build();
    ValidateMetersResult response = validationService.validateMeters(SWITCH_ID_B, singletonList(actualMeter), singletonList(expectedMeter));
    assertFalse(response.getMissingMeters().isEmpty());
    assertMeter(response.getMissingMeters().get(0), 32, 10000, 10500, new String[] { "KBPS", "BURST", "STATS" });
    assertTrue(response.getMisconfiguredMeters().isEmpty());
    assertTrue(response.getProperMeters().isEmpty());
    assertFalse(response.getExcessMeters().isEmpty());
    assertMeter(response.getExcessMeters().get(0), 33, 10000, 10500, new String[] { "KBPS", "BURST", "STATS" });
}
Also used : MeterSpeakerData(org.openkilda.rulemanager.MeterSpeakerData) ValidateMetersResult(org.openkilda.wfm.topology.switchmanager.model.ValidateMetersResult) ValidationService(org.openkilda.wfm.topology.switchmanager.service.ValidationService) MeterId(org.openkilda.model.MeterId) Test(org.junit.Test)

Example 24 with MeterId

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

the class KildaEntryCacheServiceTest method shouldCacheServiceRefreshMeterCache.

@Test
public void shouldCacheServiceRefreshMeterCache() {
    Flow flow = buildFlow();
    when(flowRepository.findAll()).thenReturn(Collections.singletonList(flow));
    service.refreshCache();
    MeterStatsData statsOriginSrc = getMeterStatsDataSrcSwitch();
    service.completeAndForwardMeterStats(statsOriginSrc);
    final MeterId forwardMeterId = flow.getForwardPath().getMeterId();
    @SuppressWarnings({ "ConstantConditions" }) final MeterId forwardProtectedMeterId = flow.getProtectedForwardPath().getMeterId();
    verify(carrier, atLeastOnce()).emitMeterStats(meterCacheCaptor.capture());
    List<MeterStatsAndDescriptor> statsEntries = meterCacheCaptor.getValue().getStatsEntries();
    assertDescriptionPopulation(statsEntries, statsOriginSrc.getStats().size(), 2);
    assertMeterCache(statsEntries, forwardMeterId.getValue(), new CommonFlowDescriptor(flow.getSrcSwitchId(), INGRESS, flow.getFlowId(), flow.getForwardPath().getCookie(), forwardMeterId));
    assertMeterCache(statsEntries, forwardProtectedMeterId.getValue(), new CommonFlowDescriptor(flow.getSrcSwitchId(), INGRESS, flow.getFlowId(), flow.getProtectedForwardPath().getCookie(), forwardProtectedMeterId));
    MeterStatsData statsOriginDst = getMeterStatsDataDstSwitch();
    service.completeAndForwardMeterStats(statsOriginDst);
    verify(carrier, atLeastOnce()).emitMeterStats(meterCacheCaptor.capture());
    statsEntries = meterCacheCaptor.getValue().getStatsEntries();
    assertDescriptionPopulation(statsEntries, statsOriginDst.getStats().size(), 2);
    final MeterId reverseMeterId = flow.getReversePath().getMeterId();
    assertMeterCache(statsEntries, reverseMeterId.getValue(), new CommonFlowDescriptor(flow.getDestSwitchId(), INGRESS, flow.getFlowId(), flow.getReversePath().getCookie(), reverseMeterId));
    final MeterId reverseProtectedMeterId = flow.getProtectedReversePath().getMeterId();
    assertMeterCache(statsEntries, reverseProtectedMeterId.getValue(), new CommonFlowDescriptor(flow.getDestSwitchId(), INGRESS, flow.getFlowId(), flow.getProtectedReversePath().getCookie(), reverseProtectedMeterId));
}
Also used : MeterStatsData(org.openkilda.messaging.info.stats.MeterStatsData) MeterStatsAndDescriptor(org.openkilda.wfm.topology.stats.model.MeterStatsAndDescriptor) CommonFlowDescriptor(org.openkilda.wfm.topology.stats.model.CommonFlowDescriptor) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) MeterId(org.openkilda.model.MeterId) Test(org.junit.Test)

Example 25 with MeterId

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

the class BroadCastDiscoveryRuleGenerator method generateCommands.

@Override
public List<SpeakerData> generateCommands(Switch sw) {
    List<SpeakerData> commands = new ArrayList<>();
    List<Action> actions = new ArrayList<>();
    Instructions instructions = Instructions.builder().applyActions(actions).build();
    FlowSpeakerData flowCommand = buildRule(sw, instructions);
    commands.add(flowCommand);
    MeterId meterId = createMeterIdForDefaultRule(VERIFICATION_BROADCAST_RULE_COOKIE);
    SpeakerData meterCommand = generateMeterCommandForServiceRule(sw, meterId, config.getBroadcastRateLimit(), config.getSystemMeterBurstSizeInPackets(), config.getDiscoPacketSize());
    if (meterCommand != null) {
        commands.add(meterCommand);
        addMeterToInstructions(meterId, sw, instructions);
    }
    GroupSpeakerData groupCommand = null;
    if (sw.getFeatures().contains(SwitchFeature.GROUP_PACKET_OUT_CONTROLLER)) {
        groupCommand = getRoundTripLatencyGroup(sw);
        actions.add(new GroupAction(groupCommand.getGroupId()));
        commands.add(groupCommand);
    } else {
        actions.add(new PortOutAction(new PortNumber(SpecialPortType.CONTROLLER)));
    }
    if (meterCommand != null) {
        flowCommand.getDependsOn().add(meterCommand.getUuid());
    }
    if (groupCommand != null) {
        flowCommand.getDependsOn().add(groupCommand.getUuid());
    }
    return commands;
}
Also used : GroupAction(org.openkilda.rulemanager.action.GroupAction) Action(org.openkilda.rulemanager.action.Action) GroupAction(org.openkilda.rulemanager.action.GroupAction) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) SetFieldAction(org.openkilda.rulemanager.action.SetFieldAction) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) ArrayList(java.util.ArrayList) GroupSpeakerData(org.openkilda.rulemanager.GroupSpeakerData) Instructions(org.openkilda.rulemanager.Instructions) PortNumber(org.openkilda.rulemanager.ProtoConstants.PortNumber) SpeakerData(org.openkilda.rulemanager.SpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) GroupSpeakerData(org.openkilda.rulemanager.GroupSpeakerData) 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