use of org.openkilda.model.cookie.FlowSegmentCookie in project open-kilda by telstra.
the class CommandBuilderImplTest method shouldBuildRemoveFlowWithoutMeterFromFlowEntryWithVxlanEncapsulationTransitAndEgress.
@Test
public void shouldBuildRemoveFlowWithoutMeterFromFlowEntryWithVxlanEncapsulationTransitAndEgress() {
Long cookie = new FlowSegmentCookie(FlowPathDirection.FORWARD, 1).getValue();
String inPort = "1";
String outPort = "2";
String tunnelId = "10";
FlowEntry flowEntry = buildFlowEntry(cookie, inPort, null, outPort, tunnelId, false, null, null);
RemoveFlow removeFlow = commandBuilder.buildRemoveFlowWithoutMeterFromFlowEntry(SWITCH_ID_A, flowEntry);
assertEquals(cookie, removeFlow.getCookie());
DeleteRulesCriteria criteria = removeFlow.getCriteria();
assertEquals(cookie, criteria.getCookie());
assertEquals(Integer.valueOf(inPort), criteria.getInPort());
assertEquals(Integer.valueOf(tunnelId), criteria.getEncapsulationId());
assertEquals(Integer.valueOf(outPort), criteria.getOutPort());
assertNull(criteria.getMetadataValue());
assertNull(criteria.getMetadataMask());
}
use of org.openkilda.model.cookie.FlowSegmentCookie in project open-kilda by telstra.
the class SwitchSyncServiceImplTest method setUp.
@Before
public void setUp() {
RepositoryFactory repositoryFactory = Mockito.mock(RepositoryFactory.class);
FlowRepository flowRepository = Mockito.mock(FlowRepository.class);
FlowPathRepository flowPathRepository = Mockito.mock(FlowPathRepository.class);
TransitVlanRepository transitVlanRepository = Mockito.mock(TransitVlanRepository.class);
when(repositoryFactory.createFlowPathRepository()).thenReturn(flowPathRepository);
when(repositoryFactory.createFlowRepository()).thenReturn(flowRepository);
when(repositoryFactory.createTransitVlanRepository()).thenReturn(transitVlanRepository);
when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory);
Properties configProps = new Properties();
configProps.setProperty("flow.meter-id.max", "40");
configProps.setProperty("flow.vlan.max", "50");
PropertiesBasedConfigurationProvider configurationProvider = new PropertiesBasedConfigurationProvider(configProps);
FlowResourcesConfig flowResourcesConfig = configurationProvider.getConfiguration(FlowResourcesConfig.class);
service = new SwitchSyncServiceImpl(carrier, persistenceManager, flowResourcesConfig);
service.commandBuilder = commandBuilder;
request = SwitchValidateRequest.builder().switchId(SWITCH_ID).performSync(true).build();
flowEntry = new FlowEntry(new FlowSegmentCookie(FlowPathDirection.FORWARD, 7).getValue(), 0, 0, 0, 0, "", 0, 0, 0, 0, null, null, null);
InstallIngressFlow installingRule = new InstallIngressFlow(UUID.randomUUID(), FLOW_ID, flowEntry.getCookie(), SWITCH_ID, 1, 2, 50, 0, 60, FlowEncapsulationType.TRANSIT_VLAN, OutputVlanType.POP, 10L, 100L, EGRESS_SWITCH_ID, false, false, false, null);
when(commandBuilder.buildCommandsToSyncMissingRules(eq(SWITCH_ID), any())).thenReturn(singletonList(installingRule));
missingRules = singletonList(flowEntry.getCookie());
excessRules = emptyList();
misconfiguredRules = emptyList();
excessMeters = emptyList();
}
use of org.openkilda.model.cookie.FlowSegmentCookie in project open-kilda by telstra.
the class CommandBuilderImpl method buildCommandsToSyncMissingRules.
@Override
public List<BaseFlow> buildCommandsToSyncMissingRules(SwitchId switchId, List<Long> switchRules) {
List<BaseFlow> commands = new ArrayList<>(buildInstallDefaultRuleCommands(switchId, switchRules));
commands.addAll(buildInstallFlowSharedRuleCommands(switchId, switchRules));
flowPathRepository.findBySegmentDestSwitch(switchId).forEach(flowPath -> {
FlowSegmentCookie mirrorCookie = flowPath.getCookie().toBuilder().mirror(true).build();
boolean switchRulesContainsFlowPathCookie = switchRules.contains(flowPath.getCookie().getValue());
boolean switchRulesContainsMirrorCookie = switchRules.contains(mirrorCookie.getValue());
if (switchRulesContainsFlowPathCookie || switchRulesContainsMirrorCookie) {
PathSegment segment = flowPath.getSegments().stream().filter(pathSegment -> pathSegment.getDestSwitchId().equals(switchId)).findAny().orElseThrow(() -> new IllegalStateException(format("PathSegment not found, path %s, switch %s", flowPath, switchId)));
log.info("Rule {} is to be (re)installed on switch {}", flowPath.getCookie(), switchId);
commands.addAll(buildInstallCommandFromSegment(flowPath, segment, switchRulesContainsFlowPathCookie, switchRulesContainsMirrorCookie));
}
});
SwitchProperties switchProperties = getSwitchProperties(switchId);
flowPathRepository.findByEndpointSwitch(switchId).forEach(flowPath -> {
FlowSegmentCookie mirrorCookie = flowPath.getCookie().toBuilder().mirror(true).build();
boolean switchRulesContainsFlowPathCookie = switchRules.contains(flowPath.getCookie().getValue());
boolean switchRulesContainsMirrorCookie = switchRules.contains(mirrorCookie.getValue());
if (switchRulesContainsFlowPathCookie || switchRulesContainsMirrorCookie) {
Flow flow = getFlow(flowPath);
if (flowPath.isOneSwitchFlow()) {
log.info("One-switch flow {} is to be (re)installed on switch {}", flowPath.getCookie(), switchId);
SwitchId swId = flowPath.isForward() ? flow.getDestSwitchId() : flow.getSrcSwitchId();
int port = flowPath.isForward() ? flow.getDestPort() : flow.getSrcPort();
if (switchRulesContainsMirrorCookie) {
MirrorConfig mirrorConfig = makeMirrorConfig(flowPath, swId, port);
commands.add(flowCommandFactory.makeOneSwitchMirrorRule(flow, flowPath, mirrorConfig));
}
if (switchRulesContainsFlowPathCookie) {
commands.add(flowCommandFactory.makeOneSwitchRule(flow, flowPath));
}
} else if (flowPath.getSrcSwitchId().equals(switchId)) {
log.info("Ingress flow {} is to be (re)installed on switch {}", flowPath.getCookie(), switchId);
if (flowPath.getSegments().isEmpty()) {
log.warn("Output port was not found for ingress flow rule");
} else {
PathSegment foundIngressSegment = flowPath.getSegments().get(0);
EncapsulationResources encapsulationResources = getEncapsulationResources(flowPath, flow);
if (switchRulesContainsMirrorCookie) {
MirrorConfig mirrorConfig = makeMirrorConfig(flowPath, foundIngressSegment.getSrcSwitchId(), foundIngressSegment.getSrcPort());
commands.add(flowCommandFactory.buildInstallIngressMirrorFlow(flow, flowPath, foundIngressSegment.getSrcPort(), encapsulationResources, foundIngressSegment.isSrcWithMultiTable(), mirrorConfig));
}
if (switchRulesContainsFlowPathCookie) {
commands.add(flowCommandFactory.buildInstallIngressFlow(flow, flowPath, foundIngressSegment.getSrcPort(), encapsulationResources, foundIngressSegment.isSrcWithMultiTable()));
}
}
}
}
long server42Cookie = flowPath.getCookie().toBuilder().type(CookieType.SERVER_42_FLOW_RTT_INGRESS).build().getValue();
if (switchRules.contains(server42Cookie) && !flowPath.isOneSwitchFlow() && flowPath.getSrcSwitchId().equals(switchId)) {
log.info("Ingress server 42 flow {} is to be (re)installed on switch {}", server42Cookie, switchId);
if (flowPath.getSegments().isEmpty()) {
log.warn("Output port was not found for server 42 ingress flow rule {}", server42Cookie);
} else {
Flow flow = getFlow(flowPath);
PathSegment foundIngressSegment = flowPath.getSegments().get(0);
EncapsulationResources encapsulationResources = getEncapsulationResources(flowPath, flow);
commands.add(flowCommandFactory.buildInstallServer42IngressFlow(flow, flowPath, foundIngressSegment.getSrcPort(), switchProperties.getServer42Port(), switchProperties.getServer42MacAddress(), encapsulationResources, foundIngressSegment.isSrcWithMultiTable()));
}
}
long loopCookie = flowPath.getCookie().toBuilder().looped(true).build().getValue();
if (switchRules.contains(loopCookie)) {
log.info("Loop rule with cookie {} is to be reinstalled on switch {}", loopCookie, switchId);
Flow flow = getFlow(flowPath);
EncapsulationResources encapsulationResources = getEncapsulationResources(flowPath, flow);
if (flowPath.getSrcSwitch().getSwitchId().equals(switchId)) {
boolean srcWithMultiTable = flowPath.getSegments().get(0).isSrcWithMultiTable();
commands.add(flowCommandFactory.buildInstallIngressLoopFlow(flow, flowPath, encapsulationResources, srcWithMultiTable));
} else {
PathSegment lastSegment = flowPath.getSegments().get(flowPath.getSegments().size() - 1);
boolean destWithMultiTable = lastSegment.isDestWithMultiTable();
commands.add(flowCommandFactory.buildInstallTransitLoopFlow(flow, flowPath, lastSegment.getDestPort(), encapsulationResources, destWithMultiTable));
}
}
});
return commands;
}
use of org.openkilda.model.cookie.FlowSegmentCookie in project open-kilda by telstra.
the class StatsTopologyTest method flowAttendantRulesStatsTest.
@Test
public void flowAttendantRulesStatsTest() {
Flow flow = createFlow();
FlowSegmentCookie server42IngressCookie = MAIN_FORWARD_COOKIE.toBuilder().type(CookieType.SERVER_42_FLOW_RTT_INGRESS).build();
FlowEndpoint ingress = new FlowEndpoint(SWITCH_ID_1, PORT_1);
FlowStatsEntry measure0 = new FlowStatsEntry(0, server42IngressCookie.getValue(), 0, 0, ingress.getPortNumber(), ingress.getPortNumber() + 1);
FlowStatsEntry measure1 = new FlowStatsEntry(0, server42IngressCookie.getValue(), 1, 200, ingress.getPortNumber(), ingress.getPortNumber() + 1);
FlowStatsEntry measure2 = new FlowStatsEntry(0, server42IngressCookie.getValue(), 2, 300, ingress.getPortNumber(), ingress.getPortNumber() + 1);
sendStatsMessage(new FlowStatsData(ingress.getSwitchId(), Collections.singletonList(measure0)));
sendUpdateFlowPathInfo(flow.getForwardPath());
sendStatsMessage(new FlowStatsData(ingress.getSwitchId(), Collections.singletonList(measure1)));
sendRemoveFlowPathInfo(flow.getForwardPath());
sendStatsMessage(new FlowStatsData(ingress.getSwitchId(), Collections.singletonList(measure2)));
List<Datapoint> datapoints = pollDatapoints(9);
List<Datapoint> rawPacketsMetric = datapoints.stream().filter(entry -> (METRIC_PREFIX + "flow.raw.packets").equals(entry.getMetric())).collect(Collectors.toList());
Assert.assertEquals(3, rawPacketsMetric.size());
for (Datapoint entry : rawPacketsMetric) {
Map<String, String> tags = entry.getTags();
Assert.assertEquals(CookieType.SERVER_42_FLOW_RTT_INGRESS.name().toLowerCase(), tags.get("type"));
if (Objects.equals(0, entry.getValue())) {
Assert.assertEquals("unknown", tags.get("flowid"));
} else if (Objects.equals(1, entry.getValue())) {
Assert.assertEquals(flowId, tags.get("flowid"));
} else if (Objects.equals(2, entry.getValue())) {
Assert.assertEquals("unknown", tags.get("flowid"));
} else {
Assert.fail(format("Unexpected metric value: %s", entry));
}
}
}
use of org.openkilda.model.cookie.FlowSegmentCookie in project open-kilda by telstra.
the class BaseCacheChangeHandler method handleStatsEntry.
@Override
public void handleStatsEntry(YFlowSubDescriptor descriptor) {
FlowSegmentCookie cookie = descriptor.getCookie();
handleFlowStatsEntry(descriptor.getSwitchId(), cookie, descriptor.getMeterId(), descriptor);
FlowSegmentCookie satelliteCookie = cookie.toBuilder().yFlow(true).build();
cacheAction(new CookieCacheKey(descriptor.getSwitchId(), satelliteCookie.getValue()), descriptor);
}
Aggregations