use of org.onosproject.net.Port in project onos by opennetworkinglab.
the class HostMonitorTest method testMonitorIpv4HostDoesNotExistWithVlan.
@Test
public void testMonitorIpv4HostDoesNotExistWithVlan() throws Exception {
HostManager hostManager = createMock(HostManager.class);
DeviceId devId = DeviceId.deviceId("fake");
short vlan = 5;
Device device = createMock(Device.class);
expect(device.id()).andReturn(devId).anyTimes();
replay(device);
PortNumber portNum = PortNumber.portNumber(1L);
Port port = createMock(Port.class);
expect(port.number()).andReturn(portNum).anyTimes();
expect(port.isEnabled()).andReturn(true).anyTimes();
replay(port);
TestDeviceService deviceService = new TestDeviceService();
deviceService.addDevice(device, Collections.singleton(port));
ConnectPoint cp = new ConnectPoint(devId, portNum);
expect(hostManager.getHostsByIp(TARGET_IPV4_ADDR)).andReturn(Collections.emptySet()).anyTimes();
replay(hostManager);
InterfaceService interfaceService = createMock(InterfaceService.class);
expect(interfaceService.getMatchingInterfaces(TARGET_IPV4_ADDR)).andReturn(Collections.singleton(new Interface(Interface.NO_INTERFACE_NAME, cp, Collections.singletonList(IA1), sourceMac, VlanId.vlanId(vlan)))).anyTimes();
replay(interfaceService);
TestPacketService packetService = new TestPacketService();
// Run the test
hostMonitor = new HostMonitor(packetService, hostManager, interfaceService, edgePortService, deviceService);
hostMonitor.addMonitoringFor(TARGET_IPV4_ADDR);
hostMonitor.run();
// Check that a packet was sent to our PacketService and that it has
// the properties we expect
assertEquals(2, packetService.packets.size());
OutboundPacket packet = packetService.packets.get(0);
// Check the output port is correct
assertEquals(1, packet.treatment().immediate().size());
Instruction instruction = packet.treatment().immediate().get(0);
assertTrue(instruction instanceof OutputInstruction);
OutputInstruction oi = (OutputInstruction) instruction;
assertEquals(portNum, oi.port());
// Check the output packet is correct (well the important bits anyway)
final byte[] pktData = new byte[packet.data().remaining()];
packet.data().get(pktData);
Ethernet eth = Ethernet.deserializer().deserialize(pktData, 0, pktData.length);
assertEquals(vlan, eth.getVlanID());
ARP arp = (ARP) eth.getPayload();
assertArrayEquals(SOURCE_IPV4_ADDR.toOctets(), arp.getSenderProtocolAddress());
assertArrayEquals(sourceMac.toBytes(), arp.getSenderHardwareAddress());
assertArrayEquals(TARGET_IPV4_ADDR.toOctets(), arp.getTargetProtocolAddress());
}
use of org.onosproject.net.Port in project onos by opennetworkinglab.
the class FlowStatisticManager method loadTopnByType.
@Override
public Map<ConnectPoint, List<FlowEntryWithLoad>> loadTopnByType(Device device, FlowEntry.FlowLiveType liveType, Instruction.Type instType, int topn) {
checkPermission(STATISTIC_READ);
Map<ConnectPoint, List<FlowEntryWithLoad>> allLoad = new TreeMap<>(Comparators.CONNECT_POINT_COMPARATOR);
if (device == null) {
return allLoad;
}
List<Port> ports = new ArrayList<>(deviceService.getPorts(device.id()));
for (Port port : ports) {
ConnectPoint cp = new ConnectPoint(device.id(), port.number());
List<FlowEntryWithLoad> fel = loadTopnPortInternal(cp, liveType, instType, topn);
allLoad.put(cp, fel);
}
return allLoad;
}
use of org.onosproject.net.Port in project onos by opennetworkinglab.
the class ResourceDeviceListener method queryBandwidth.
/**
* Query bandwidth capacity on a port.
*
* @param did {@link DeviceId}
* @param number {@link PortNumber}
* @return bandwidth capacity
*/
private Optional<Bandwidth> queryBandwidth(DeviceId did, PortNumber number) {
// Check and use netcfg first.
ConnectPoint cp = new ConnectPoint(did, number);
BandwidthCapacity config = netcfgService.getConfig(cp, BandwidthCapacity.class);
if (config != null) {
log.trace("Registering configured bandwidth {} for {}/{}", config.capacity(), did, number);
return Optional.of(config.capacity());
}
// populate bandwidth value, assuming portSpeed == bandwidth
Port port = deviceService.getPort(did, number);
if (port != null) {
return Optional.of(Bandwidth.mbps(port.portSpeed()));
}
return Optional.empty();
}
use of org.onosproject.net.Port in project onos by opennetworkinglab.
the class DefaultKubevirtNodeHandler method isDeviceCreatedStateDone.
private boolean isDeviceCreatedStateDone(KubevirtNode node) {
try {
// we need to wait a while, in case tunneling ports
// creation requires some time
sleep(SLEEP_MID_MS);
} catch (InterruptedException e) {
log.error("Exception caused during init state checking...");
}
if (node.dataIp() != null && !isIntfEnabled(node, VXLAN)) {
log.warn("VXLAN interface is not enabled!");
return false;
}
if (node.dataIp() != null && !isIntfEnabled(node, GRE)) {
log.warn("GRE interface is not enabled!");
return false;
}
if (node.dataIp() != null && !isIntfEnabled(node, GENEVE)) {
log.warn("GENEVE interface is not enabled!");
return false;
}
for (KubevirtPhyInterface phyIntf : node.phyIntfs()) {
if (phyIntf == null) {
log.warn("Physnet interface is invalid");
return false;
}
try {
// we need to wait a while, in case tunneling ports
// creation requires some time
sleep(SLEEP_LONG_MS);
} catch (InterruptedException e) {
log.error("Exception caused during init state checking...");
}
String patchPortName = structurePortName(INTEGRATION_TO_PHYSICAL_PREFIX + phyIntf.network());
if (node.type() == WORKER) {
String bridgeName = BRIDGE_PREFIX + phyIntf.network();
if (!(hasPhyBridge(node, bridgeName) && hasPhyPatchPort(node, patchPortName) && hasPhyIntf(node, phyIntf.intf()))) {
log.warn("PhyBridge {}", hasPhyBridge(node, bridgeName));
log.warn("hasPhyPatchPort {}", hasPhyPatchPort(node, patchPortName));
log.warn("hasPhyIntf {}", hasPhyIntf(node, phyIntf.intf()));
return false;
}
} else {
// In case node type is GATEWAY, we create physical bridges connected to the contoller.
// By doing so, ONOS immediately recognizes the status of physical interface and performs RM procedures.
Port phyIntfPort = deviceService.getPorts(phyIntf.physBridge()).stream().filter(port -> port.annotations().value(PORT_NAME).equals(phyIntf.intf())).findAny().orElse(null);
if (phyIntfPort == null) {
log.warn("There's no connected physical port {} on physical device {}", phyIntf.intf(), phyIntf.physBridge());
}
if (!(deviceService.isAvailable(phyIntf.physBridge()) && hasPhyPatchPort(node, patchPortName) && hasPhyIntf(node, phyIntf.intf()) && phyIntfPort.isEnabled())) {
log.warn("PhysBridge {}", deviceService.isAvailable(phyIntf.physBridge()));
log.warn("hasPhyPatchPort {}", hasPhyPatchPort(node, patchPortName));
log.warn("hasPhyIntf {}", hasPhyIntf(node, phyIntf.intf()));
log.warn("physical interface port {}", phyIntfPort.isEnabled());
return false;
}
}
}
if (node.type() == GATEWAY) {
if (!(hasPhyIntf(node, INTEGRATION_TO_TUNNEL) && hasPhyIntf(node, TUNNEL_TO_INTEGRATION))) {
log.warn("IntToTunPort {}", hasPhyIntf(node, INTEGRATION_TO_TUNNEL));
log.warn("TunToIntPort {}", hasPhyIntf(node, TUNNEL_TO_INTEGRATION));
return false;
}
}
return true;
}
use of org.onosproject.net.Port in project onos by opennetworkinglab.
the class DefaultKubevirtNode method tunnelPort.
private PortNumber tunnelPort(String tunnelType) {
if (dataIp == null) {
return null;
}
DeviceService deviceService = DefaultServiceDirectory.getService(DeviceService.class);
Port port = deviceService.getPorts(tunBridge).stream().filter(p -> p.isEnabled() && Objects.equals(p.annotations().value(PORT_NAME), tunnelType)).findAny().orElse(null);
return port != null ? port.number() : null;
}
Aggregations