use of org.openkilda.model.SwitchProperties in project open-kilda by telstra.
the class PersistenceDataAdapterTest method shouldKeepMultitableForFlowInSwitchProperties.
@Test
public void shouldKeepMultitableForFlowInSwitchProperties() {
Set<SwitchId> switchIds = Sets.newHashSet(SWITCH_ID_1, SWITCH_ID_2);
Switch sw1 = buildSwitch(SWITCH_ID_1, singleton(SwitchFeature.MULTI_TABLE));
SwitchProperties switchProperties1 = buildSwitchProperties(sw1, false);
Switch sw2 = buildSwitch(SWITCH_ID_2, singleton(SwitchFeature.MULTI_TABLE));
SwitchProperties switchProperties2 = buildSwitchProperties(sw2, true);
Map<SwitchId, SwitchProperties> switchProperties = new HashMap<>();
switchProperties.put(SWITCH_ID_1, switchProperties1);
switchProperties.put(SWITCH_ID_2, switchProperties2);
when(switchPropertiesRepository.findBySwitchIds(switchIds)).thenReturn(switchProperties);
when(flowRepository.findByEndpointSwitchWithMultiTableSupport(SWITCH_ID_1)).thenReturn(singleton(mock(Flow.class)));
adapter = PersistenceDataAdapter.builder().switchIds(switchIds).persistenceManager(persistenceManager).keepMultitableForFlow(true).build();
assertTrue(adapter.getSwitchProperties(SWITCH_ID_1).isMultiTable());
assertTrue(adapter.getSwitchProperties(SWITCH_ID_2).isMultiTable());
}
use of org.openkilda.model.SwitchProperties in project open-kilda by telstra.
the class FlowPathBuilder method buildPathSegments.
/**
* Build a path segments using provided path.
*
* @param pathId a pathId the segments will be associated with.
* @param pathForSegments path to be used for the segments.
* @param bandwidth bandwidth to be used for the segments.
* @param ignoreBandwidth ignore bandwidth be used for the segments.
* @param sharedBandwidthGroupId a shared bandwidth group to be set for the segments
*/
public List<PathSegment> buildPathSegments(PathId pathId, Path pathForSegments, long bandwidth, boolean ignoreBandwidth, String sharedBandwidthGroupId) {
Map<SwitchId, SwitchProperties> switchProperties = getSwitchProperties(pathId);
List<PathSegment> result = new ArrayList<>();
for (int i = 0; i < pathForSegments.getSegments().size(); i++) {
Path.Segment segment = pathForSegments.getSegments().get(i);
SwitchProperties srcSwitchProperties = switchProperties.get(segment.getSrcSwitchId());
SwitchProperties dstSwitchProperties = switchProperties.get(segment.getDestSwitchId());
result.add(PathSegment.builder().seqId(i).pathId(pathId).srcSwitch(Switch.builder().switchId(segment.getSrcSwitchId()).build()).srcPort(segment.getSrcPort()).srcWithMultiTable(srcSwitchProperties.isMultiTable()).destSwitch(Switch.builder().switchId(segment.getDestSwitchId()).build()).destPort(segment.getDestPort()).destWithMultiTable(dstSwitchProperties.isMultiTable()).latency(segment.getLatency()).bandwidth(bandwidth).ignoreBandwidth(ignoreBandwidth).sharedBandwidthGroupId(sharedBandwidthGroupId).build());
}
return result;
}
use of org.openkilda.model.SwitchProperties in project open-kilda by telstra.
the class BaseResourceAllocationAction method updateSwitchRelatedFlowProperties.
private void updateSwitchRelatedFlowProperties(Flow flow) {
Map<SwitchId, SwitchProperties> switchProperties = LazyMap.lazyMap(new HashMap<>(), switchId -> switchPropertiesRepository.findBySwitchId(switchId).orElse(null));
DetectConnectedDevices.DetectConnectedDevicesBuilder detectConnectedDevices = flow.getDetectConnectedDevices().toBuilder();
SwitchProperties srcSwitchProps = switchProperties.get(flow.getSrcSwitchId());
if (srcSwitchProps != null) {
detectConnectedDevices.srcSwitchLldp(srcSwitchProps.isSwitchLldp());
detectConnectedDevices.srcSwitchArp(srcSwitchProps.isSwitchArp());
}
SwitchProperties destSwitchProps = switchProperties.get(flow.getDestSwitchId());
if (destSwitchProps != null) {
switchProperties.put(flow.getDestSwitchId(), destSwitchProps);
detectConnectedDevices.dstSwitchLldp(destSwitchProps.isSwitchLldp());
detectConnectedDevices.dstSwitchArp(destSwitchProps.isSwitchArp());
}
flow.setDetectConnectedDevices(detectConnectedDevices.build());
}
use of org.openkilda.model.SwitchProperties in project open-kilda by telstra.
the class BaseFlowRuleRemovalAction method buildSpeakerContextForRemovalIngressAndShared.
protected SpeakerRequestBuildContext buildSpeakerContextForRemovalIngressAndShared(RequestedFlow oldFlow, RequestedFlow newFlow, boolean removeMeters) {
SwitchProperties srcSwitchProperties = getSwitchProperties(oldFlow.getSrcSwitch());
boolean server42FlowRttToggle = isServer42FlowRttFeatureToggle();
boolean srcServer42FlowRtt = srcSwitchProperties.isServer42FlowRtt() && server42FlowRttToggle;
FlowEndpoint oldIngress = new FlowEndpoint(oldFlow.getSrcSwitch(), oldFlow.getSrcPort(), oldFlow.getSrcVlan(), oldFlow.getSrcInnerVlan());
FlowEndpoint oldEgress = new FlowEndpoint(oldFlow.getDestSwitch(), oldFlow.getDestPort(), oldFlow.getDestVlan(), oldFlow.getDestInnerVlan());
FlowEndpoint newIngress = new FlowEndpoint(newFlow.getSrcSwitch(), newFlow.getSrcPort(), newFlow.getSrcVlan(), newFlow.getSrcInnerVlan());
FlowEndpoint newEgress = new FlowEndpoint(newFlow.getDestSwitch(), newFlow.getDestPort(), newFlow.getDestVlan(), newFlow.getDestInnerVlan());
PathContext forwardPathContext = PathContext.builder().removeCustomerPortRule(removeForwardCustomerPortSharedCatchRule(oldFlow, newFlow)).removeCustomerPortLldpRule(removeForwardSharedLldpRule(oldFlow, newFlow)).removeCustomerPortArpRule(removeForwardSharedArpRule(oldFlow, newFlow)).removeOuterVlanMatchSharedRule(removeOuterVlanMatchSharedRule(oldFlow.getFlowId(), oldIngress, newIngress)).removeServer42InputRule(removeForwardSharedServer42InputRule(oldFlow, newFlow, srcServer42FlowRtt)).removeServer42IngressRule(srcServer42FlowRtt).updateMeter(removeMeters).removeServer42OuterVlanMatchSharedRule(srcServer42FlowRtt && removeServer42OuterVlanMatchSharedRule(oldFlow, oldIngress, newIngress)).server42Port(srcSwitchProperties.getServer42Port()).server42MacAddress(srcSwitchProperties.getServer42MacAddress()).build();
SwitchProperties dstSwitchProperties = getSwitchProperties(oldFlow.getDestSwitch());
boolean dstServer42FlowRtt = dstSwitchProperties.isServer42FlowRtt() && server42FlowRttToggle;
PathContext reversePathContext = PathContext.builder().removeCustomerPortRule(removeReverseCustomerPortSharedCatchRule(oldFlow, newFlow)).removeCustomerPortLldpRule(removeReverseSharedLldpRule(oldFlow, newFlow)).removeCustomerPortArpRule(removeReverseSharedArpRule(oldFlow, newFlow)).removeOuterVlanMatchSharedRule(removeOuterVlanMatchSharedRule(oldFlow.getFlowId(), oldEgress, newEgress)).removeServer42InputRule(removeReverseSharedServer42InputRule(oldFlow, newFlow, dstServer42FlowRtt)).removeServer42IngressRule(dstServer42FlowRtt).updateMeter(removeMeters).removeServer42OuterVlanMatchSharedRule(dstServer42FlowRtt && removeServer42OuterVlanMatchSharedRule(oldFlow, oldEgress, newEgress)).server42Port(dstSwitchProperties.getServer42Port()).server42MacAddress(dstSwitchProperties.getServer42MacAddress()).build();
return SpeakerRequestBuildContext.builder().forward(forwardPathContext).reverse(reversePathContext).build();
}
use of org.openkilda.model.SwitchProperties in project open-kilda by telstra.
the class FlowValidator method checkForConnectedDevisesConflict.
private void checkForConnectedDevisesConflict(String flowId, SwitchId switchId) throws InvalidFlowException {
SwitchProperties properties = switchPropertiesRepository.findBySwitchId(switchId).orElseThrow(() -> new InvalidFlowException(format("Couldn't get switch properties for switch %s.", switchId), ErrorType.DATA_INVALID));
if (properties.isSwitchLldp() || properties.isSwitchArp()) {
String errorMessage = format("Connected devices feature is active on the switch %s, " + "flow mirror point cannot be created on this switch.", switchId);
throw new InvalidFlowException(errorMessage, ErrorType.PARAMETERS_INVALID);
}
Optional<Flow> foundFlow = flowRepository.findById(flowId);
if (foundFlow.isPresent()) {
Flow flow = foundFlow.get();
FlowEndpoint source = new FlowSourceAdapter(flow).getEndpoint();
FlowEndpoint destination = new FlowDestAdapter(flow).getEndpoint();
if (switchId.equals(source.getSwitchId())) {
if (source.isTrackLldpConnectedDevices() || source.isTrackArpConnectedDevices()) {
String errorMessage = format("Connected devices feature is active on the flow %s for endpoint %s, " + "flow mirror point cannot be created this flow", flow.getFlowId(), source);
throw new InvalidFlowException(errorMessage, ErrorType.PARAMETERS_INVALID);
}
} else {
if (destination.isTrackLldpConnectedDevices() || destination.isTrackArpConnectedDevices()) {
String errorMessage = format("Connected devices feature is active on the flow %s for endpoint %s, " + "flow mirror point cannot be created this flow", flow.getFlowId(), destination);
throw new InvalidFlowException(errorMessage, ErrorType.PARAMETERS_INVALID);
}
}
}
}
Aggregations