use of org.openkilda.model.FlowPath in project open-kilda by telstra.
the class CommandBuilderImpl method buildGroupInstallContexts.
@Override
public List<GroupInstallContext> buildGroupInstallContexts(SwitchId switchId, List<Integer> groupIds) {
List<GroupInstallContext> groupInstallContexts = new ArrayList<>();
Map<PathId, MirrorGroup> mirrorGroups = new HashMap<>();
groupIds.stream().map(GroupId::new).map(mirrorGroupRepository::findByGroupId).flatMap(o -> o.map(Stream::of).orElseGet(Stream::empty)).forEach(mirrorGroup -> mirrorGroups.put(mirrorGroup.getPathId(), mirrorGroup));
flowPathRepository.findBySegmentDestSwitch(switchId).forEach(flowPath -> {
if (mirrorGroups.containsKey(flowPath.getPathId())) {
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)));
Flow flow = flowPath.getFlow();
if (segment.getDestSwitchId().equals(flowPath.getDestSwitchId())) {
MirrorConfig mirrorConfig = makeMirrorConfig(flowPath, flow.getDestSwitchId(), flow.getDestPort());
groupInstallContexts.add(GroupInstallContext.builder().mirrorConfig(mirrorConfig).build());
log.info("Group {} is to be (re)installed on switch {}", mirrorConfig.getGroupId(), switchId);
}
}
});
flowPathRepository.findByEndpointSwitch(switchId).forEach(flowPath -> {
if (mirrorGroups.containsKey(flowPath.getPathId())) {
Flow flow = getFlow(flowPath);
if (flowPath.isOneSwitchFlow()) {
SwitchId swId = flowPath.isForward() ? flow.getDestSwitchId() : flow.getSrcSwitchId();
int port = flowPath.isForward() ? flow.getDestPort() : flow.getSrcPort();
MirrorConfig mirrorConfig = makeMirrorConfig(flowPath, swId, port);
groupInstallContexts.add(GroupInstallContext.builder().mirrorConfig(mirrorConfig).build());
log.info("Group {} is to be (re)installed on switch {}", mirrorConfig.getGroupId(), switchId);
} else if (flowPath.getSrcSwitchId().equals(switchId)) {
if (flowPath.getSegments().isEmpty()) {
log.warn("Output port was not found for mirror config");
} else {
PathSegment foundIngressSegment = flowPath.getSegments().get(0);
MirrorConfig mirrorConfig = makeMirrorConfig(flowPath, foundIngressSegment.getSrcSwitchId(), foundIngressSegment.getSrcPort());
EncapsulationResources encapsulation = getEncapsulationResources(flowPath, flow);
groupInstallContexts.add(GroupInstallContext.builder().mirrorConfig(mirrorConfig).encapsulation(new FlowTransitEncapsulation(encapsulation.getTransitEncapsulationId(), encapsulation.getEncapsulationType())).egressSwitchId(flowPath.getDestSwitchId()).build());
log.info("Group {} is to be (re)installed on switch {}", mirrorConfig.getGroupId(), switchId);
}
}
}
});
return groupInstallContexts;
}
use of org.openkilda.model.FlowPath in project open-kilda by telstra.
the class TransitRuleGeneratorTest method buildOneSwitchFlowTransitRuleTest.
@Test
public void buildOneSwitchFlowTransitRuleTest() {
FlowPath path = FlowPath.builder().pathId(PATH_ID).cookie(COOKIE).srcSwitch(SWITCH_1).destSwitch(SWITCH_1).build();
TransitRuleGenerator generator = TransitRuleGenerator.builder().flowPath(path).inPort(PORT_NUMBER_1).outPort(PORT_NUMBER_2).multiTable(true).encapsulation(VLAN_ENCAPSULATION).build();
assertEquals(0, generator.generateCommands(SWITCH_1).size());
}
use of org.openkilda.model.FlowPath in project open-kilda by telstra.
the class PersistenceDataAdapterTest method shouldProvideCorrectFlowPaths.
@Test
public void shouldProvideCorrectFlowPaths() {
PathId pathId = new PathId("path1");
Set<PathId> pathIds = Sets.newHashSet(pathId);
FlowPath flowPath = FlowPath.builder().pathId(pathId).srcSwitch(buildSwitch(SWITCH_ID_1, Collections.emptySet())).destSwitch(buildSwitch(SWITCH_ID_2, Collections.emptySet())).build();
Map<PathId, FlowPath> flowPaths = new HashMap<>();
flowPaths.put(pathId, flowPath);
when(flowPathRepository.findByIds(pathIds)).thenReturn(flowPaths);
adapter = PersistenceDataAdapter.builder().pathIds(pathIds).persistenceManager(persistenceManager).build();
Map<PathId, FlowPath> actual = adapter.getFlowPaths();
assertEquals(1, actual.size());
assertEquals(flowPath, actual.get(pathId));
adapter.getFlowPaths();
verify(flowPathRepository).findByIds(pathIds);
verifyNoMoreInteractions(flowPathRepository);
}
use of org.openkilda.model.FlowPath in project open-kilda by telstra.
the class EgressMirrorRuleGeneratorTest method buildVxlanMultiTableOuterVlanEgressMirrorRuleTest.
@Test
public void buildVxlanMultiTableOuterVlanEgressMirrorRuleTest() {
FlowPath path = buildPathWithMirror(true);
Flow flow = buildFlow(path, OUTER_VLAN_ID, 0);
EgressMirrorRuleGenerator generator = buildGenerator(path, flow, VXLAN_ENCAPSULATION);
List<SpeakerData> commands = generator.generateCommands(SWITCH_2);
assertEquals(2, commands.size());
FlowSpeakerData egressCommand = getCommand(FlowSpeakerData.class, commands);
GroupSpeakerData groupCommand = getCommand(GroupSpeakerData.class, commands);
ArrayList<Action> expectedApplyActions = Lists.newArrayList(new PopVxlanAction(ActionType.POP_VXLAN_NOVIFLOW), new PushVlanAction(), SetFieldAction.builder().field(Field.VLAN_VID).value(OUTER_VLAN_ID).build(), new GroupAction(GROUP_ID));
assertEgressCommand(egressCommand, OfTable.EGRESS, VXLAN_ENCAPSULATION, expectedApplyActions, groupCommand.getUuid());
assertGroupCommand(groupCommand);
}
use of org.openkilda.model.FlowPath in project open-kilda by telstra.
the class EgressMirrorRuleGeneratorTest method buildVlanSingleTableFullPortEgressMirrorRuleTest.
@Test
public void buildVlanSingleTableFullPortEgressMirrorRuleTest() {
FlowPath path = buildPathWithMirror(false);
Flow flow = buildFlow(path, 0, 0);
EgressMirrorRuleGenerator generator = buildGenerator(path, flow, VLAN_ENCAPSULATION);
List<SpeakerData> commands = generator.generateCommands(SWITCH_2);
assertEquals(2, commands.size());
FlowSpeakerData egressCommand = getCommand(FlowSpeakerData.class, commands);
GroupSpeakerData groupCommand = getCommand(GroupSpeakerData.class, commands);
ArrayList<Action> expectedApplyActions = Lists.newArrayList(new PopVlanAction(), new GroupAction(GROUP_ID));
assertEgressCommand(egressCommand, OfTable.INPUT, VLAN_ENCAPSULATION, expectedApplyActions, groupCommand.getUuid());
assertGroupCommand(groupCommand);
}
Aggregations