use of org.openkilda.model.MeterId in project open-kilda by telstra.
the class UnicastVerificationVxlanRuleGenerator method generateCommands.
@Override
public List<SpeakerData> generateCommands(Switch sw) {
// should be replaced with fair feature detection based on ActionId's during handshake
if (!(sw.getFeatures().contains(NOVIFLOW_PUSH_POP_VXLAN) || sw.getFeatures().contains(KILDA_OVS_PUSH_POP_MATCH_VXLAN))) {
return Collections.emptyList();
}
Cookie cookie = new Cookie(VERIFICATION_UNICAST_VXLAN_RULE_COOKIE);
FlowSpeakerData flowCommand = buildUnicastVerificationRuleVxlan(sw, cookie);
List<SpeakerData> result = new ArrayList<>();
result.add(flowCommand);
MeterId meterId = createMeterIdForDefaultRule(cookie.getValue());
long meterRate = config.getUnicastRateLimit();
MeterSpeakerData meterCommand = generateMeterCommandForServiceRule(sw, meterId, meterRate, config.getSystemMeterBurstSizeInPackets(), config.getDiscoPacketSize());
if (meterCommand != null) {
addMeterToInstructions(meterId, sw, flowCommand.getInstructions());
flowCommand.getDependsOn().add(meterCommand.getUuid());
result.add(meterCommand);
}
return result;
}
use of org.openkilda.model.MeterId in project open-kilda by telstra.
the class FlowPathBuilderTest method shouldBuildFlowPathFor3SwitchPath.
@Test
public void shouldBuildFlowPathFor3SwitchPath() {
SwitchId switchId1 = new SwitchId(1);
SwitchId switchId2 = new SwitchId(2);
SwitchId switchId3 = new SwitchId(3);
Path path = Path.builder().srcSwitchId(switchId1).destSwitchId(switchId2).segments(asList(Segment.builder().srcSwitchId(switchId1).srcPort(1).destSwitchId(switchId3).destPort(2).build(), Segment.builder().srcSwitchId(switchId3).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(2));
}
use of org.openkilda.model.MeterId in project open-kilda by telstra.
the class FlowPathBuilderTest method shouldBuildFlowPathFor1SwitchPath.
@Test
public void shouldBuildFlowPathFor1SwitchPath() {
SwitchId switchId = new SwitchId(1);
Path path = Path.builder().srcSwitchId(switchId).destSwitchId(switchId).segments(Collections.emptyList()).build();
Flow flow = Flow.builder().flowId("test_flow").srcSwitch(Switch.builder().switchId(switchId).build()).destSwitch(Switch.builder().switchId(switchId).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(pathId, flowPath.getPathId());
assertEquals(meterId, flowPath.getMeterId());
assertEquals(cookie, flowPath.getCookie());
assertThat(flowPath.getSegments(), empty());
}
use of org.openkilda.model.MeterId in project open-kilda by telstra.
the class IngressInstallFlowModFactory method makeForwardMessageInstructions.
protected List<OFInstruction> makeForwardMessageInstructions(EffectiveIds effectiveIds, List<Integer> vlanStack) {
List<OFAction> applyActions = new ArrayList<>();
List<OFInstruction> instructions = new ArrayList<>();
MeterId effectiveMeterId = effectiveIds.getMeterId();
if (effectiveMeterId != null) {
OfAdapter.INSTANCE.makeMeterCall(of, effectiveMeterId, applyActions, instructions);
}
GroupId effectiveGroupId = effectiveIds.getGroupId();
boolean groupIsPresent = effectiveGroupId != null;
applyActions.addAll(makeTransformActions(vlanStack, groupIsPresent));
if (groupIsPresent) {
applyActions.add(makeGroupAction(effectiveGroupId));
} else {
applyActions.add(makeOutputAction());
}
instructions.add(of.instructions().applyActions(applyActions));
if (command.getMetadata().isMultiTable() && effectiveGroupId == null) {
instructions.add(of.instructions().gotoTable(TableId.of(SwitchManager.POST_INGRESS_TABLE_ID)));
instructions.addAll(makeMetadataInstructions());
}
return instructions;
}
use of org.openkilda.model.MeterId in project open-kilda by telstra.
the class IngressFlowSegmentBase method planOfFlowsInstall.
private CompletableFuture<FlowSegmentReport> planOfFlowsInstall(EffectiveIds effectiveIds) {
MeterId effectiveMeterId = effectiveIds.getMeterId();
MeterConfig meterConfig = getMeterConfig();
if (effectiveMeterId == null && rulesContext != null && !rulesContext.isUpdateMeter() && meterConfig != null) {
effectiveIds.setMeterId(meterConfig.getId());
}
List<OFFlowMod> ofMessages = makeFlowModMessages(effectiveIds);
List<CompletableFuture<Optional<OFMessage>>> writeResults = new ArrayList<>(ofMessages.size());
try (Session session = getSessionService().open(messageContext, getSw())) {
for (OFFlowMod message : ofMessages) {
writeResults.add(session.write(message));
}
}
return CompletableFuture.allOf(writeResults.toArray(new CompletableFuture[0])).thenApply(ignore -> makeSuccessReport());
}
Aggregations