use of org.openkilda.model.SwitchProperties in project open-kilda by telstra.
the class SwitchRuleServiceImpl method installRules.
@Override
public void installRules(String key, SwitchRulesInstallRequest data) {
isOperationCompleted = false;
SwitchId switchId = data.getSwitchId();
if (!switchRepository.exists(switchId)) {
ErrorData errorData = new ErrorData(ErrorType.NOT_FOUND, format("Switch %s not found", switchId), "Error when installing switch rules");
ErrorMessage errorMessage = new ErrorMessage(errorData, System.currentTimeMillis(), key);
carrier.response(key, errorMessage);
return;
}
Optional<SwitchProperties> switchProperties = switchPropertiesRepository.findBySwitchId(switchId);
KildaFeatureToggles featureToggles = featureTogglesRepository.getOrDefault();
boolean server42FlowRttFeatureToggle = featureToggles.getServer42FlowRtt();
data.setServer42FlowRttFeatureToggle(server42FlowRttFeatureToggle);
data.setServer42IslRttEnabled(featureToggles.getServer42IslRtt() && switchProperties.map(SwitchProperties::hasServer42IslRttEnabled).orElse(false));
if (switchProperties.isPresent()) {
data.setMultiTable(switchProperties.get().isMultiTable());
data.setSwitchLldp(switchProperties.get().isSwitchLldp());
data.setSwitchArp(switchProperties.get().isSwitchArp());
data.setServer42FlowRttSwitchProperty(switchProperties.get().isServer42FlowRtt());
data.setServer42Port(switchProperties.get().getServer42Port());
data.setServer42Vlan(switchProperties.get().getServer42Vlan());
data.setServer42MacAddress(switchProperties.get().getServer42MacAddress());
Collection<FlowPath> flowPaths = flowPathRepository.findBySrcSwitch(switchId);
List<Integer> flowPorts = new ArrayList<>();
Set<Integer> flowLldpPorts = new HashSet<>();
Set<Integer> flowArpPorts = new HashSet<>();
Set<Integer> server42FlowPorts = new HashSet<>();
fillFlowPorts(switchProperties.get(), flowPaths, flowPorts, flowLldpPorts, flowArpPorts, server42FlowPorts, server42FlowRttFeatureToggle && switchProperties.get().isServer42FlowRtt());
data.setFlowPorts(flowPorts);
data.setFlowLldpPorts(flowLldpPorts);
data.setFlowArpPorts(flowArpPorts);
data.setServer42FlowRttPorts(server42FlowPorts);
List<Integer> islPorts = islRepository.findBySrcSwitch(switchId).stream().map(isl -> isl.getSrcPort()).collect(Collectors.toList());
data.setIslPorts(islPorts);
}
carrier.sendCommandToSpeaker(key, data);
}
use of org.openkilda.model.SwitchProperties in project open-kilda by telstra.
the class SwitchRuleServiceImpl method deleteRules.
@Override
public void deleteRules(String key, SwitchRulesDeleteRequest data) {
isOperationCompleted = false;
SwitchId switchId = data.getSwitchId();
if (!switchRepository.exists(switchId)) {
ErrorData errorData = new ErrorData(ErrorType.NOT_FOUND, format("Switch %s not found", switchId), "Error when deleting switch rules");
ErrorMessage errorMessage = new ErrorMessage(errorData, System.currentTimeMillis(), key);
carrier.response(key, errorMessage);
return;
}
Optional<SwitchProperties> switchProperties = switchPropertiesRepository.findBySwitchId(switchId);
KildaFeatureToggles featureToggles = featureTogglesRepository.getOrDefault();
boolean server42FlowRttFeatureToggle = featureToggles.getServer42FlowRtt();
data.setServer42FlowRttFeatureToggle(server42FlowRttFeatureToggle);
data.setServer42IslRttEnabled(featureToggles.getServer42IslRtt() && switchProperties.map(SwitchProperties::hasServer42IslRttEnabled).orElse(false));
if (switchProperties.isPresent()) {
data.setMultiTable(switchProperties.get().isMultiTable());
data.setSwitchLldp(switchProperties.get().isSwitchLldp());
data.setSwitchArp(switchProperties.get().isSwitchArp());
data.setServer42FlowRttSwitchProperty(switchProperties.get().isServer42FlowRtt());
data.setServer42Port(switchProperties.get().getServer42Port());
data.setServer42Vlan(switchProperties.get().getServer42Vlan());
data.setServer42MacAddress(switchProperties.get().getServer42MacAddress());
Collection<FlowPath> flowPaths = flowPathRepository.findBySrcSwitch(switchId);
List<Integer> flowPorts = new ArrayList<>();
Set<Integer> flowLldpPorts = new HashSet<>();
Set<Integer> flowArpPorts = new HashSet<>();
Set<Integer> server42FlowPorts = new HashSet<>();
fillFlowPorts(switchProperties.get(), flowPaths, flowPorts, flowLldpPorts, flowArpPorts, server42FlowPorts, server42FlowRttFeatureToggle && switchProperties.get().isServer42FlowRtt());
data.setFlowPorts(flowPorts);
data.setFlowLldpPorts(flowLldpPorts);
data.setFlowArpPorts(flowArpPorts);
data.setServer42FlowRttPorts(server42FlowPorts);
List<Integer> islPorts = islRepository.findBySrcSwitch(switchId).stream().map(isl -> isl.getSrcPort()).collect(Collectors.toList());
data.setIslPorts(islPorts);
}
carrier.sendCommandToSpeaker(key, data);
}
use of org.openkilda.model.SwitchProperties in project open-kilda by telstra.
the class ResourceAllocationAction method allocate.
@Override
protected void allocate(FlowMirrorPointCreateFsm stateMachine) throws RecoverableException, UnroutableFlowException, ResourceAllocationException {
RequestedFlowMirrorPoint mirrorPoint = stateMachine.getRequestedFlowMirrorPoint();
transactionManager.doInTransaction(() -> {
Flow flow = getFlow(mirrorPoint.getFlowId());
FlowPath flowPath = getFlowPath(mirrorPoint, flow);
stateMachine.setFlowPathId(flowPath.getPathId());
Optional<FlowMirrorPoints> foundFlowMirrorPoints = flowMirrorPointsRepository.findByPathIdAndSwitchId(flowPath.getPathId(), mirrorPoint.getMirrorPointSwitchId());
FlowMirrorPoints flowMirrorPoints;
if (foundFlowMirrorPoints.isPresent()) {
flowMirrorPoints = foundFlowMirrorPoints.get();
} else {
flowMirrorPoints = createFlowMirrorPoints(mirrorPoint, flowPath);
stateMachine.setAddNewGroup(true);
}
Switch sinkSwitch = switchRepository.findById(mirrorPoint.getSinkEndpoint().getSwitchId()).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Switch %s not found", mirrorPoint.getSinkEndpoint().getSwitchId())));
stateMachine.setUnmaskedCookie(resourcesManager.getAllocatedCookie(flow.getFlowId()));
FlowSegmentCookie cookie = FlowSegmentCookie.builder().flowEffectiveId(stateMachine.getUnmaskedCookie()).mirror(true).build();
SwitchProperties switchProperties = getSwitchProperties(sinkSwitch.getSwitchId());
boolean dstWithMultiTable = switchProperties != null ? switchProperties.isMultiTable() : kildaConfigurationRepository.getOrDefault().getUseMultiTable();
FlowMirrorPath flowMirrorPath = FlowMirrorPath.builder().pathId(stateMachine.getMirrorPathId()).mirrorSwitch(flowMirrorPoints.getMirrorSwitch()).egressSwitch(sinkSwitch).egressPort(mirrorPoint.getSinkEndpoint().getPortNumber()).egressOuterVlan(mirrorPoint.getSinkEndpoint().getOuterVlanId()).egressInnerVlan(mirrorPoint.getSinkEndpoint().getInnerVlanId()).cookie(cookie).bandwidth(flow.getBandwidth()).ignoreBandwidth(flow.isIgnoreBandwidth()).status(FlowPathStatus.IN_PROGRESS).egressWithMultiTable(dstWithMultiTable).build();
flowMirrorPathRepository.add(flowMirrorPath);
flowMirrorPoints.addPaths(flowMirrorPath);
// TODO: add path allocation in case when src switch is not equal to dst switch
});
stateMachine.saveActionToHistory("New mirror path was created", format("The flow mirror path %s was created (with allocated resources)", stateMachine.getMirrorPathId()));
}
use of org.openkilda.model.SwitchProperties in project open-kilda by telstra.
the class FermaSwitchPropertiesRepositoryTest method shouldCreateSwitchPropertiesWithRelation.
@Test
public void shouldCreateSwitchPropertiesWithRelation() {
Switch origSwitch = Switch.builder().switchId(TEST_SWITCH_ID).description("Some description").build();
switchRepository.add(origSwitch);
SwitchProperties switchProperties = SwitchProperties.builder().switchObj(origSwitch).supportedTransitEncapsulation(SwitchProperties.DEFAULT_FLOW_ENCAPSULATION_TYPES).build();
switchPropertiesRepository.add(switchProperties);
List<SwitchProperties> switchPropertiesResult = new ArrayList<>(switchPropertiesRepository.findAll());
assertEquals(1, switchPropertiesResult.size());
assertNotNull(switchPropertiesResult.get(0).getSwitchObj());
}
use of org.openkilda.model.SwitchProperties in project open-kilda by telstra.
the class FermaSwitchPropertiesRepositoryTest method shouldCreatePropertiesWithServer42Props.
@Test
public void shouldCreatePropertiesWithServer42Props() {
Switch origSwitch = Switch.builder().switchId(TEST_SWITCH_ID).description("Some description").build();
switchRepository.add(origSwitch);
SwitchProperties switchProperties = SwitchProperties.builder().switchObj(origSwitch).server42FlowRtt(true).server42Port(SERVER_42_PORT).server42Vlan(SERVER_42_VLAN).server42MacAddress(SERVER_42_MAC_ADDRESS).supportedTransitEncapsulation(SwitchProperties.DEFAULT_FLOW_ENCAPSULATION_TYPES).build();
switchPropertiesRepository.add(switchProperties);
Optional<SwitchProperties> switchPropertiesOptional = switchPropertiesRepository.findBySwitchId(TEST_SWITCH_ID);
assertTrue(switchPropertiesOptional.isPresent());
assertTrue(switchPropertiesOptional.get().isServer42FlowRtt());
assertEquals(SERVER_42_PORT, switchPropertiesOptional.get().getServer42Port());
assertEquals(SERVER_42_VLAN, switchPropertiesOptional.get().getServer42Vlan());
assertEquals(SERVER_42_MAC_ADDRESS, switchPropertiesOptional.get().getServer42MacAddress());
}
Aggregations