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