use of org.openkilda.messaging.model.grpc.LogicalPort in project open-kilda by telstra.
the class ValidationServiceImpl method validateLogicalPorts.
@Override
public ValidateLogicalPortsResult validateLogicalPorts(SwitchId switchId, List<LogicalPort> presentLogicalPorts) {
Map<Integer, LogicalPortInfoEntry> expectedPorts = lagLogicalPortRepository.findBySwitchId(switchId).stream().map(LogicalPortMapper.INSTANCE::map).peek(port -> Collections.sort(port.getPhysicalPorts())).collect(Collectors.toMap(LogicalPortInfoEntry::getLogicalPortNumber, Function.identity()));
Map<Integer, LogicalPortInfoEntry> actualPorts = presentLogicalPorts.stream().map(LogicalPortMapper.INSTANCE::map).peek(port -> Collections.sort(port.getPhysicalPorts())).collect(Collectors.toMap(LogicalPortInfoEntry::getLogicalPortNumber, Function.identity()));
List<LogicalPortInfoEntry> properPorts = new ArrayList<>();
List<LogicalPortInfoEntry> missingPorts = new ArrayList<>();
List<LogicalPortInfoEntry> excessPorts = new ArrayList<>();
List<LogicalPortInfoEntry> misconfiguredPorts = new ArrayList<>();
for (Entry<Integer, LogicalPortInfoEntry> entry : expectedPorts.entrySet()) {
int portNumber = entry.getKey();
LogicalPortInfoEntry expected = entry.getValue();
if (actualPorts.containsKey(portNumber)) {
LogicalPortInfoEntry actual = actualPorts.get(portNumber);
if (actual.equals(expected)) {
properPorts.add(actual);
} else {
misconfiguredPorts.add(calculateMisconfiguredLogicalPort(expected, actual));
}
} else {
missingPorts.add(expected);
}
}
for (Entry<Integer, LogicalPortInfoEntry> entry : actualPorts.entrySet()) {
if (LogicalPortType.BFD.equals(entry.getValue().getType())) {
// At this moment we do not validate BFD ports, so Kilda wouldn't include BFD ports into excess list
continue;
}
if (!expectedPorts.containsKey(entry.getKey())) {
excessPorts.add(entry.getValue());
}
}
return new ValidateLogicalPortsResult(ImmutableList.copyOf(properPorts), ImmutableList.copyOf(missingPorts), ImmutableList.copyOf(excessPorts), ImmutableList.copyOf(misconfiguredPorts));
}
use of org.openkilda.messaging.model.grpc.LogicalPort in project open-kilda by telstra.
the class ValidationServiceImplTest method validateLogicalPorts.
@Test
public void validateLogicalPorts() {
ValidationService validationService = new ValidationServiceImpl(persistenceManager().build());
LogicalPort proper = buildLogicalPort(LOGICAL_PORT_NUMBER_1, PHYSICAL_PORT_2, PHYSICAL_PORT_1);
LogicalPort misconfigured = buildLogicalPort(LOGICAL_PORT_NUMBER_2, LogicalPortType.BFD, PHYSICAL_PORT_3);
LogicalPort excess = buildLogicalPort(LOGICAL_PORT_NUMBER_4, PHYSICAL_PORT_6);
LogicalPort bfdExcess = buildLogicalPort(LOGICAL_PORT_NUMBER_5, LogicalPortType.BFD, PHYSICAL_PORT_7);
ValidateLogicalPortsResult result = validationService.validateLogicalPorts(SWITCH_ID_A, Lists.newArrayList(proper, misconfigured, excess, bfdExcess));
assertEquals(1, result.getProperLogicalPorts().size());
// bfdExcess port shouldn't be in this list
assertEquals(1, result.getExcessLogicalPorts().size());
assertEquals(1, result.getMissingLogicalPorts().size());
assertEquals(1, result.getMisconfiguredLogicalPorts().size());
assertEqualLogicalPort(proper, result.getProperLogicalPorts().get(0));
assertEqualLogicalPort(excess, result.getExcessLogicalPorts().get(0));
LogicalPortInfoEntry missing = LogicalPortInfoEntry.builder().type(org.openkilda.messaging.info.switches.LogicalPortType.LAG).logicalPortNumber(LOGICAL_PORT_NUMBER_3).physicalPorts(Lists.newArrayList(PHYSICAL_PORT_5, PHYSICAL_PORT_6)).build();
assertEquals(missing, result.getMissingLogicalPorts().get(0));
LogicalPortInfoEntry misconfiguredEntry = LogicalPortInfoEntry.builder().type(org.openkilda.messaging.info.switches.LogicalPortType.BFD).logicalPortNumber(LOGICAL_PORT_NUMBER_2).physicalPorts(Lists.newArrayList(PHYSICAL_PORT_3)).actual(new LogicalPortMisconfiguredInfoEntry(org.openkilda.messaging.info.switches.LogicalPortType.BFD, Lists.newArrayList(PHYSICAL_PORT_3))).expected(new LogicalPortMisconfiguredInfoEntry(org.openkilda.messaging.info.switches.LogicalPortType.LAG, Lists.newArrayList(PHYSICAL_PORT_3, PHYSICAL_PORT_4))).build();
assertEquals(misconfiguredEntry, result.getMisconfiguredLogicalPorts().get(0));
}
use of org.openkilda.messaging.model.grpc.LogicalPort in project open-kilda by telstra.
the class LogicalPortMapperTest method mapLogicalPortTest.
@Test
public void mapLogicalPortTest() {
LogicalPort logicalPort = LogicalPort.builder().logicalPortNumber(LAG_PORT).portNumbers(Lists.newArrayList(PHYSICAL_PORT_1, PHYSICAL_PORT_2)).type(LogicalPortType.LAG).name("some").build();
LogicalPortInfoEntry port = INSTANCE.map(logicalPort);
assertEquals(LAG_PORT, port.getLogicalPortNumber().intValue());
assertEquals(2, port.getPhysicalPorts().size());
assertEquals(PHYSICAL_PORT_1, port.getPhysicalPorts().get(0).intValue());
assertEquals(PHYSICAL_PORT_2, port.getPhysicalPorts().get(1).intValue());
assertNull(port.getExpected());
assertNull(port.getActual());
}
Aggregations