use of org.openkilda.model.Switch in project open-kilda by telstra.
the class SwitchValidateFsm method emitRequests.
public void emitRequests(SwitchValidateState from, SwitchValidateState to, SwitchValidateEvent event, SwitchValidateContext context) {
try {
SwitchId switchId = getSwitchId();
log.info("The switch validate process for {} has been started (key={})", switchId, key);
// FIXME(surabujin): not reliable check - corresponding error from speaker is much more better
Optional<Switch> sw = switchRepository.findById(switchId);
if (!sw.isPresent()) {
throw new SwitchNotFoundException(switchId);
}
requestSwitchOfFlows();
requestSwitchOfGroups();
if (sw.get().getFeatures().contains(LAG)) {
// at this moment Kilda validated only LAG logical ports
Optional<String> ipAddress = sw.map(Switch::getSocketAddress).map(IpSocketAddress::getAddress);
if (ipAddress.isPresent()) {
requestLogicalPorts(ipAddress.get());
} else {
log.warn("Unable to get IP address of switch {} to get LAGs", switchId);
}
}
if (request.isProcessMeters()) {
requestSwitchMeters();
}
} catch (Exception ex) {
log.error("Failure in emitRequests", ex);
throw ex;
}
}
use of org.openkilda.model.Switch in project open-kilda by telstra.
the class SwitchMapperTest method testSwitchToSwitchDto.
@Test
public void testSwitchToSwitchDto() {
Switch sw = getSwitch();
SwitchDto switchDto = switchMapper.toSwitchDto(sw);
assertEquals(sw.getSwitchId(), switchDto.getSwitchId());
assertEquals("127.0.0.1", switchDto.getAddress());
assertEquals(sw.getSocketAddress().getPort(), switchDto.getPort());
assertEquals(sw.getHostname(), switchDto.getHostname());
assertEquals(sw.getDescription(), switchDto.getDescription());
assertEquals(switchMapper.convertStatus(sw.getStatus()), switchDto.getState());
assertEquals(sw.isUnderMaintenance(), switchDto.isUnderMaintenance());
assertEquals(sw.getOfVersion(), switchDto.getOfVersion());
assertEquals(sw.getOfDescriptionManufacturer(), switchDto.getManufacturer());
assertEquals(sw.getOfDescriptionHardware(), switchDto.getHardware());
assertEquals(sw.getOfDescriptionSoftware(), switchDto.getSoftware());
assertEquals(sw.getOfDescriptionSerialNumber(), switchDto.getSerialNumber());
assertEquals(sw.getPop(), switchDto.getPop());
assertEquals((Double) sw.getLatitude(), switchDto.getLocation().getLatitude());
assertEquals((Double) sw.getLongitude(), switchDto.getLocation().getLongitude());
assertEquals(sw.getStreet(), switchDto.getLocation().getStreet());
assertEquals(sw.getCity(), switchDto.getLocation().getCity());
assertEquals(sw.getCountry(), switchDto.getLocation().getCountry());
}
use of org.openkilda.model.Switch in project open-kilda by telstra.
the class SwitchMapperTest method testSwitchToSwitchDtoV2.
@Test
public void testSwitchToSwitchDtoV2() {
Switch sw = getSwitch();
SwitchDtoV2 switchDto = switchMapper.map(sw);
assertEquals(sw.getSwitchId(), switchDto.getSwitchId());
assertEquals("127.0.0.1", switchDto.getAddress());
assertEquals(sw.getSocketAddress().getPort(), switchDto.getPort());
assertEquals(sw.getHostname(), switchDto.getHostname());
assertEquals(sw.getDescription(), switchDto.getDescription());
assertEquals(switchMapper.convertStatus(sw.getStatus()), switchDto.getState());
assertEquals(sw.isUnderMaintenance(), switchDto.isUnderMaintenance());
assertEquals(sw.getOfVersion(), switchDto.getOfVersion());
assertEquals(sw.getOfDescriptionManufacturer(), switchDto.getManufacturer());
assertEquals(sw.getOfDescriptionHardware(), switchDto.getHardware());
assertEquals(sw.getOfDescriptionSoftware(), switchDto.getSoftware());
assertEquals(sw.getOfDescriptionSerialNumber(), switchDto.getSerialNumber());
assertEquals(sw.getPop(), switchDto.getPop());
assertEquals((Double) sw.getLatitude(), switchDto.getLocation().getLatitude());
assertEquals((Double) sw.getLongitude(), switchDto.getLocation().getLongitude());
assertEquals(sw.getStreet(), switchDto.getLocation().getStreet());
assertEquals(sw.getCity(), switchDto.getLocation().getCity());
assertEquals(sw.getCountry(), switchDto.getLocation().getCountry());
}
use of org.openkilda.model.Switch in project open-kilda by telstra.
the class PersistenceDataAdapterTest method shouldProvideCorrectSwitchProperties.
@Test
public void shouldProvideCorrectSwitchProperties() {
Set<SwitchId> switchIds = Sets.newHashSet(SWITCH_ID_1, SWITCH_ID_2);
Switch sw1 = buildSwitch(SWITCH_ID_1, Collections.emptySet());
SwitchProperties switchProperties1 = buildSwitchProperties(sw1, false);
Switch sw2 = buildSwitch(SWITCH_ID_2, Collections.emptySet());
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);
adapter = PersistenceDataAdapter.builder().switchIds(switchIds).persistenceManager(persistenceManager).build();
assertEquals(switchProperties1, adapter.getSwitchProperties(SWITCH_ID_1));
assertEquals(switchProperties2, adapter.getSwitchProperties(SWITCH_ID_2));
verify(switchPropertiesRepository).findBySwitchIds(switchIds);
verifyNoMoreInteractions(switchPropertiesRepository);
}
use of org.openkilda.model.Switch in project open-kilda by telstra.
the class RuleManagerImpl method buildRulesForFlowPath.
@Override
public List<SpeakerData> buildRulesForFlowPath(FlowPath flowPath, boolean filterOutUsedSharedRules, DataAdapter adapter) {
List<SpeakerData> result = new ArrayList<>();
Flow flow = adapter.getFlow(flowPath.getPathId());
PathId oppositePathId = flow.getOppositePathId(flowPath.getPathId()).orElse(null);
FlowTransitEncapsulation encapsulation = adapter.getTransitEncapsulation(flowPath.getPathId(), oppositePathId);
if (!flow.isProtectedPath(flowPath.getPathId())) {
Set<FlowSideAdapter> overlappingAdapters = new HashSet<>();
if (filterOutUsedSharedRules) {
overlappingAdapters = getOverlappingMultiTableIngressAdapters(flowPath, adapter);
}
buildIngressCommands(adapter.getSwitch(flowPath.getSrcSwitchId()), flowPath, flow, encapsulation, overlappingAdapters, adapter.getSwitchProperties(flowPath.getSrcSwitchId()), adapter.getFeatureToggles());
}
if (flowPath.isOneSwitchFlow()) {
return result;
}
result.addAll(buildEgressCommands(adapter.getSwitch(flowPath.getDestSwitchId()), flowPath, flow, encapsulation));
for (int i = 1; i < flowPath.getSegments().size(); i++) {
PathSegment firstSegment = flowPath.getSegments().get(i - 1);
PathSegment secondSegment = flowPath.getSegments().get(i);
result.addAll(buildTransitCommands(adapter.getSwitch(firstSegment.getDestSwitchId()), flowPath, encapsulation, firstSegment, secondSegment));
}
if (flow.isLooped()) {
Switch loopedSwitch = adapter.getSwitch(flow.getLoopSwitchId());
result.addAll(buildTransitLoopCommands(loopedSwitch, flowPath, flow, encapsulation));
}
return postProcessCommands(result);
}
Aggregations