use of org.openkilda.model.LagLogicalPort in project open-kilda by telstra.
the class FermaLagLogicalPortTest method createLogicalPortAndSetPhysicalPortsTest.
@Test
public void createLogicalPortAndSetPhysicalPortsTest() {
LagLogicalPort logicalPort = createLogicalPort(SWITCH_ID_1, LOGICAL_PORT_NUMBER_1);
assertEquals(0, lagLogicalPortRepository.findAll().iterator().next().getPhysicalPorts().size());
PhysicalPort physicalPort1 = createPhysicalPort(SWITCH_ID_1, PHYSICAL_PORT_NUMBER_1, logicalPort);
PhysicalPort physicalPort2 = createPhysicalPort(SWITCH_ID_1, PHYSICAL_PORT_NUMBER_2, logicalPort);
logicalPort.setPhysicalPorts(Lists.newArrayList(physicalPort1, physicalPort2));
List<LagLogicalPort> ports = new ArrayList<>(lagLogicalPortRepository.findAll());
assertEquals(1, ports.size());
assertEquals(2, ports.get(0).getPhysicalPorts().size());
assertEquals(PHYSICAL_PORT_NUMBER_1, ports.get(0).getPhysicalPorts().get(0).getPortNumber());
assertEquals(PHYSICAL_PORT_NUMBER_2, ports.get(0).getPhysicalPorts().get(1).getPortNumber());
assertEquals(SWITCH_ID_1, ports.get(0).getPhysicalPorts().get(0).getSwitchId());
assertEquals(SWITCH_ID_1, ports.get(0).getPhysicalPorts().get(1).getSwitchId());
assertEquals(logicalPort, ports.get(0).getPhysicalPorts().get(0).getLagLogicalPort());
assertEquals(logicalPort, ports.get(0).getPhysicalPorts().get(1).getLagLogicalPort());
}
use of org.openkilda.model.LagLogicalPort in project open-kilda by telstra.
the class FermaLagLogicalPortTest method createLogicalPort.
private LagLogicalPort createLogicalPort(SwitchId switchId, int logicalPortNumber, Integer... physicalPorts) {
LagLogicalPort port = new LagLogicalPort(switchId, logicalPortNumber, Arrays.asList(physicalPorts));
lagLogicalPortRepository.add(port);
return port;
}
use of org.openkilda.model.LagLogicalPort in project open-kilda by telstra.
the class LagPortMapperTest method mapLagPortToDtoTest.
@Test
public void mapLagPortToDtoTest() {
LagLogicalPort lagLogicalPort = new LagLogicalPort(SWITCH_ID, LAG_PORT, Lists.newArrayList(PHYSICAL_PORT_1, PHYSICAL_PORT_2));
LagPortDto dto = LagPortMapper.INSTANCE.map(lagLogicalPort);
assertEquals(LAG_PORT, dto.getLogicalPortNumber());
assertEquals(PHYSICAL_PORT_1, dto.getPortNumbers().get(0).intValue());
assertEquals(PHYSICAL_PORT_2, dto.getPortNumbers().get(1).intValue());
}
use of org.openkilda.model.LagLogicalPort in project open-kilda by telstra.
the class SwitchOperationsServiceTest method shouldReturnLagPorts.
@Test
public void shouldReturnLagPorts() throws SwitchNotFoundException {
Switch sw = Switch.builder().switchId(TEST_SWITCH_ID).status(SwitchStatus.ACTIVE).build();
switchRepository.add(sw);
LagLogicalPort lagLogicalPort = new LagLogicalPort(TEST_SWITCH_ID, LAG_LOGICAL_PORT, Lists.newArrayList(PHYSICAL_PORT_1, PHYSICAL_PORT_2));
lagLogicalPortRepository.add(lagLogicalPort);
Collection<LagLogicalPort> ports = switchOperationsService.getSwitchLagPorts(TEST_SWITCH_ID);
assertEquals(1, ports.size());
assertEquals(LAG_LOGICAL_PORT, ports.iterator().next().getLogicalPortNumber());
assertEquals(PHYSICAL_PORT_1, ports.iterator().next().getPhysicalPorts().get(0).getPortNumber());
assertEquals(PHYSICAL_PORT_2, ports.iterator().next().getPhysicalPorts().get(1).getPortNumber());
}
use of org.openkilda.model.LagLogicalPort in project open-kilda by telstra.
the class LagPortOperationService method createTransaction.
private LagLogicalPort createTransaction(SwitchId switchId, Set<Integer> targetPorts) {
// locate switch first to produce correct error if switch is missing
Switch sw = querySwitch(switchId);
if (!isSwitchLagCapable(sw)) {
throw new InvalidDataException(format("Switch %s doesn't support LAG.", sw.getSwitchId()));
}
Set<SwitchFeature> features = sw.getFeatures();
for (Integer portNumber : targetPorts) {
validatePhysicalPort(switchId, features, portNumber);
}
ensureNoLagCollisions(switchId, targetPorts);
LagLogicalPort port = queryPoolManager(switchId).allocate();
port.setPhysicalPorts(targetPorts.stream().map(portNumber -> new PhysicalPort(switchId, portNumber, port)).collect(Collectors.toList()));
log.info("Adding new LAG logical port entry into DB: {}", port);
lagLogicalPortRepository.add(port);
return port;
}
Aggregations