use of org.openkilda.model.Switch in project open-kilda by telstra.
the class RuleManagerImpl method buildIngressYFlowCommands.
private List<SpeakerData> buildIngressYFlowCommands(FlowPath flowPath, FlowPath altFlowPath, DataAdapter adapter) {
Flow flow = adapter.getFlow(flowPath.getPathId());
Flow altFlow = adapter.getFlow(altFlowPath.getPathId());
if (flow.isProtectedPath(flowPath.getPathId()) || altFlow.isProtectedPath(altFlowPath.getPathId())) {
return Collections.emptyList();
}
YFlow yFlow = adapter.getYFlow(flowPath.getPathId());
if (yFlow == null) {
return Collections.emptyList();
}
SwitchId sharedSwitchId = yFlow.getSharedEndpoint().getSwitchId();
Switch sharedSwitch = adapter.getSwitch(sharedSwitchId);
if (sharedSwitch == null || !sharedSwitchId.equals(flowPath.getSrcSwitchId()) || !sharedSwitchId.equals(altFlowPath.getSrcSwitchId())) {
return Collections.emptyList();
}
FlowTransitEncapsulation encapsulation = getFlowTransitEncapsulation(flowPath.getPathId(), flow, adapter);
FlowTransitEncapsulation altEncapsulation = getFlowTransitEncapsulation(altFlowPath.getPathId(), altFlow, adapter);
MeterId sharedMeterId = yFlow.getSharedEndpointMeterId();
RuleGenerator generator = flowRulesFactory.getIngressYRuleGenerator(flowPath, flow, encapsulation, new HashSet<>(), altFlowPath, altFlow, altEncapsulation, new HashSet<>(), sharedMeterId);
return generator.generateCommands(sharedSwitch);
}
use of org.openkilda.model.Switch in project open-kilda by telstra.
the class RuleManagerImpl method buildRulesForSwitch.
@Override
public List<SpeakerData> buildRulesForSwitch(SwitchId switchId, DataAdapter adapter) {
Switch sw = adapter.getSwitch(switchId);
List<SpeakerData> result = buildServiceRules(sw, adapter);
result.addAll(buildFlowRulesForSwitch(switchId, adapter));
return postProcessCommands(result);
}
use of org.openkilda.model.Switch 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.Switch in project open-kilda by telstra.
the class PersistenceDataAdapter method getSwitchProperties.
@Override
public SwitchProperties getSwitchProperties(SwitchId switchId) {
if (switchPropertiesCache == null) {
switchPropertiesCache = switchPropertiesRepository.findBySwitchIds(switchIds);
if (keepMultitableForFlow) {
// Override the multitable flag with actual flow data.
for (SwitchProperties switchProps : switchPropertiesCache.values()) {
SwitchId swId = switchProps.getSwitchId();
Switch sw = switchProps.getSwitchObj();
if (!switchProps.isMultiTable() && sw.supports(SwitchFeature.MULTI_TABLE) && (!flowPathRepository.findBySegmentSwitchWithMultiTable(swId, true).isEmpty() || !flowRepository.findByEndpointSwitchWithMultiTableSupport(swId).isEmpty())) {
switchPropertiesRepository.detach(switchProps);
switchProps.setMultiTable(true);
}
}
}
}
return switchPropertiesCache.get(switchId);
}
use of org.openkilda.model.Switch in project open-kilda by telstra.
the class Server42FlowRttOutputVlanRuleGeneratorTest method shouldBuildCorrectRuleForOf13.
@Test
public void shouldBuildCorrectRuleForOf13() {
Switch sw = buildSwitch("OF_13", Sets.newHashSet(NOVIFLOW_COPY_FIELD));
List<SpeakerData> commands = generator.generateCommands(sw);
assertEquals(1, commands.size());
FlowSpeakerData flowCommandData = getCommand(FlowSpeakerData.class, commands);
assertEquals(sw.getSwitchId(), flowCommandData.getSwitchId());
assertEquals(sw.getOfVersion(), flowCommandData.getOfVersion().toString());
assertTrue(flowCommandData.getDependsOn().isEmpty());
assertEquals(new Cookie(SERVER_42_FLOW_RTT_OUTPUT_VLAN_COOKIE), flowCommandData.getCookie());
assertEquals(OfTable.INPUT, flowCommandData.getTable());
assertEquals(SERVER_42_FLOW_RTT_OUTPUT_VLAN_PRIORITY, flowCommandData.getPriority());
Set<FieldMatch> expectedMatch = Sets.newHashSet(FieldMatch.builder().field(Field.ETH_DST).value(sw.getSwitchId().toMacAddressAsLong()).build(), FieldMatch.builder().field(Field.ETH_TYPE).value(EthType.IPv4).build(), FieldMatch.builder().field(Field.IP_PROTO).value(IpProto.UDP).build(), FieldMatch.builder().field(Field.UDP_SRC).value(SERVER_42_FLOW_RTT_REVERSE_UDP_PORT).build(), FieldMatch.builder().field(Field.UDP_DST).value(SERVER_42_FLOW_RTT_FORWARD_UDP_PORT).build());
assertEquals(expectedMatch, flowCommandData.getMatch());
List<Action> expectedApplyActions = Lists.newArrayList(new PushVlanAction(), SetFieldAction.builder().field(Field.VLAN_VID).value(Utils.SERVER_42_VLAN).build(), SetFieldAction.builder().field(Field.ETH_SRC).value(sw.getSwitchId().toMacAddressAsLong()).build(), SetFieldAction.builder().field(Field.ETH_DST).value(Utils.SERVER_42_MAC_ADDRESS.toLong()).build(), CopyFieldAction.builder().oxmSrcHeader(OpenFlowOxms.NOVIFLOW_TX_TIMESTAMP).oxmDstHeader(OpenFlowOxms.NOVIFLOW_UDP_PAYLOAD_OFFSET).srcOffset(0).dstOffset(NOVIFLOW_TIMESTAMP_SIZE_IN_BITS).numberOfBits(NOVIFLOW_TIMESTAMP_SIZE_IN_BITS).build(), new PortOutAction(new PortNumber(Utils.SERVER_42_PORT)));
Instructions expectedInstructions = Instructions.builder().applyActions(expectedApplyActions).build();
assertEquals(expectedInstructions, flowCommandData.getInstructions());
}
Aggregations