Search in sources :

Example 6 with VirtualPort

use of org.onosproject.incubator.net.virtual.VirtualPort in project onos by opennetworkinglab.

the class VirtualNetworkDeviceManagerTest method testDeviceEventsForAddRemovalDeviceAndPorts.

/**
 * Tests DeviceEvents received during virtual device/port addition and removal.
 */
@Test
public void testDeviceEventsForAddRemovalDeviceAndPorts() throws TestUtils.TestUtilsException {
    manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
    VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
    // add virtual device before virtual device manager is created
    VirtualDevice device1 = manager.createVirtualDevice(virtualNetwork.id(), VDID1);
    // no DeviceEvent expected
    validateEvents();
    testDirectory.add(EventDeliveryService.class, dispatcher);
    DeviceService deviceService = manager.get(virtualNetwork.id(), DeviceService.class);
    // virtual device manager is created; register DeviceEvent listener
    deviceService.addListener(testListener);
    // list to keep track of expected event types
    List<DeviceEvent.Type> expectedEventTypes = new ArrayList<>();
    // add virtual device
    VirtualDevice device2 = manager.createVirtualDevice(virtualNetwork.id(), VDID2);
    expectedEventTypes.add(DeviceEvent.Type.DEVICE_ADDED);
    ConnectPoint cp = new ConnectPoint(PHYDID1, PortNumber.portNumber(1));
    // add 2 virtual ports
    manager.createVirtualPort(virtualNetwork.id(), device2.id(), PortNumber.portNumber(1), cp);
    expectedEventTypes.add(DeviceEvent.Type.PORT_ADDED);
    manager.createVirtualPort(virtualNetwork.id(), device2.id(), PortNumber.portNumber(2), cp);
    expectedEventTypes.add(DeviceEvent.Type.PORT_ADDED);
    // verify virtual ports were added
    Set<VirtualPort> virtualPorts = manager.getVirtualPorts(virtualNetwork.id(), device2.id());
    assertNotNull("The virtual port set should not be null", virtualPorts);
    assertEquals("The virtual port set size did not match.", 2, virtualPorts.size());
    virtualPorts.forEach(vp -> assertFalse("Initial virtual port state should be disabled", vp.isEnabled()));
    // verify change state of virtual port (disabled -> enabled)
    manager.updatePortState(virtualNetwork.id(), device2.id(), PortNumber.portNumber(1), true);
    Port changedPort = deviceService.getPort(device2.id(), PortNumber.portNumber(1));
    assertNotNull("The changed virtual port should not be null", changedPort);
    assertEquals("Virtual port state should be enabled", true, changedPort.isEnabled());
    expectedEventTypes.add(DeviceEvent.Type.PORT_UPDATED);
    // verify change state of virtual port (disabled -> disabled)
    manager.updatePortState(virtualNetwork.id(), device2.id(), PortNumber.portNumber(2), false);
    changedPort = deviceService.getPort(device2.id(), PortNumber.portNumber(2));
    assertNotNull("The changed virtual port should not be null", changedPort);
    assertEquals("Virtual port state should be disabled", false, changedPort.isEnabled());
    // remove 2 virtual ports
    for (VirtualPort virtualPort : virtualPorts) {
        manager.removeVirtualPort(virtualNetwork.id(), (DeviceId) virtualPort.element().id(), virtualPort.number());
        expectedEventTypes.add(DeviceEvent.Type.PORT_REMOVED);
        // attempt to remove the same virtual port again - no DeviceEvent.Type.PORT_REMOVED expected.
        manager.removeVirtualPort(virtualNetwork.id(), (DeviceId) virtualPort.element().id(), virtualPort.number());
    }
    // verify virtual ports were removed
    virtualPorts = manager.getVirtualPorts(virtualNetwork.id(), device2.id());
    assertTrue("The virtual port set should be empty.", virtualPorts.isEmpty());
    // Add/remove one virtual port again.
    VirtualPort virtualPort = manager.createVirtualPort(virtualNetwork.id(), device2.id(), PortNumber.portNumber(1), cp);
    expectedEventTypes.add(DeviceEvent.Type.PORT_ADDED);
    ConnectPoint newCp = new ConnectPoint(PHYDID3, PortNumber.portNumber(2));
    manager.bindVirtualPort(virtualNetwork.id(), device2.id(), PortNumber.portNumber(1), newCp);
    expectedEventTypes.add(DeviceEvent.Type.PORT_UPDATED);
    manager.removeVirtualPort(virtualNetwork.id(), (DeviceId) virtualPort.element().id(), virtualPort.number());
    expectedEventTypes.add(DeviceEvent.Type.PORT_REMOVED);
    // verify no virtual ports remain
    virtualPorts = manager.getVirtualPorts(virtualNetwork.id(), device2.id());
    assertTrue("The virtual port set should be empty.", virtualPorts.isEmpty());
    // remove virtual device
    manager.removeVirtualDevice(virtualNetwork.id(), device2.id());
    expectedEventTypes.add(DeviceEvent.Type.DEVICE_REMOVED);
    // Validate that the events were all received in the correct order.
    validateEvents((Enum[]) expectedEventTypes.toArray(new DeviceEvent.Type[expectedEventTypes.size()]));
    // cleanup
    deviceService.removeListener(testListener);
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) DeviceEvent(org.onosproject.net.device.DeviceEvent) Port(org.onosproject.net.Port) VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) DeviceService(org.onosproject.net.device.DeviceService) ArrayList(java.util.ArrayList) ConnectPoint(org.onosproject.net.ConnectPoint) Test(org.junit.Test)

Example 7 with VirtualPort

use of org.onosproject.incubator.net.virtual.VirtualPort in project onos by opennetworkinglab.

the class VirtualNetworkDeviceManagerTest method testGetPort.

/**
 * Tests querying the port of a device by device identifier and port number.
 */
@Test
public void testGetPort() {
    manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
    VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
    VirtualDevice virtualDevice = manager.createVirtualDevice(virtualNetwork.id(), DID1);
    manager.createVirtualDevice(virtualNetwork.id(), DID2);
    DeviceService deviceService = manager.get(virtualNetwork.id(), DeviceService.class);
    ConnectPoint cp = new ConnectPoint(virtualDevice.id(), PortNumber.portNumber(1));
    VirtualPort virtualPort1 = manager.createVirtualPort(virtualNetwork.id(), virtualDevice.id(), PortNumber.portNumber(1), cp);
    manager.createVirtualPort(virtualNetwork.id(), virtualDevice.id(), PortNumber.portNumber(2), cp);
    // test the getPort() method
    assertEquals("The port did not match as expected.", virtualPort1, deviceService.getPort(DID1, PortNumber.portNumber(1)));
    assertNotEquals("The port did not match as expected.", virtualPort1, deviceService.getPort(DID1, PortNumber.portNumber(3)));
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) DeviceService(org.onosproject.net.device.DeviceService) ConnectPoint(org.onosproject.net.ConnectPoint) Test(org.junit.Test)

Example 8 with VirtualPort

use of org.onosproject.incubator.net.virtual.VirtualPort in project onos by opennetworkinglab.

the class VirtualNetworkManagerTest method testAddRemoveVirtualPort.

/**
 * Tests add, bind and remove of virtual ports.
 */
@Test
public void testAddRemoveVirtualPort() {
    List<VirtualNetworkEvent.Type> expectedEventTypes = new ArrayList<>();
    manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
    expectedEventTypes.add(VirtualNetworkEvent.Type.TENANT_REGISTERED);
    VirtualNetwork virtualNetwork1 = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
    expectedEventTypes.add(VirtualNetworkEvent.Type.NETWORK_ADDED);
    VirtualDevice virtualDevice = manager.createVirtualDevice(virtualNetwork1.id(), DID1);
    expectedEventTypes.add(VirtualNetworkEvent.Type.VIRTUAL_DEVICE_ADDED);
    ConnectPoint cp = new ConnectPoint(virtualDevice.id(), PortNumber.portNumber(1));
    manager.createVirtualPort(virtualNetwork1.id(), virtualDevice.id(), PortNumber.portNumber(1), cp);
    expectedEventTypes.add(VirtualNetworkEvent.Type.VIRTUAL_PORT_ADDED);
    manager.createVirtualPort(virtualNetwork1.id(), virtualDevice.id(), PortNumber.portNumber(2), cp);
    expectedEventTypes.add(VirtualNetworkEvent.Type.VIRTUAL_PORT_ADDED);
    Set<VirtualPort> virtualPorts = manager.getVirtualPorts(virtualNetwork1.id(), virtualDevice.id());
    assertNotNull("The virtual port set should not be null", virtualPorts);
    assertEquals("The virtual port set size did not match.", 2, virtualPorts.size());
    virtualPorts.forEach(vp -> assertFalse("Initial virtual port state should be disabled", vp.isEnabled()));
    // verify change state of virtual port (disabled -> enabled)
    manager.updatePortState(virtualNetwork1.id(), virtualDevice.id(), PortNumber.portNumber(1), true);
    VirtualPort changedPort = getPort(virtualNetwork1.id(), virtualDevice.id(), PortNumber.portNumber(1));
    assertNotNull("The changed virtual port should not be null", changedPort);
    assertEquals("Virtual port state should be enabled", true, changedPort.isEnabled());
    expectedEventTypes.add(VirtualNetworkEvent.Type.VIRTUAL_PORT_UPDATED);
    // verify change state of virtual port (disabled -> disabled)
    manager.updatePortState(virtualNetwork1.id(), virtualDevice.id(), PortNumber.portNumber(2), false);
    changedPort = getPort(virtualNetwork1.id(), virtualDevice.id(), PortNumber.portNumber(2));
    assertNotNull("The changed virtual port should not be null", changedPort);
    assertEquals("Virtual port state should be disabled", false, changedPort.isEnabled());
    for (VirtualPort virtualPort : virtualPorts) {
        manager.removeVirtualPort(virtualNetwork1.id(), (DeviceId) virtualPort.element().id(), virtualPort.number());
        expectedEventTypes.add(VirtualNetworkEvent.Type.VIRTUAL_PORT_REMOVED);
        // attempt to remove the same virtual port again.
        manager.removeVirtualPort(virtualNetwork1.id(), (DeviceId) virtualPort.element().id(), virtualPort.number());
    }
    virtualPorts = manager.getVirtualPorts(virtualNetwork1.id(), virtualDevice.id());
    assertTrue("The virtual port set should be empty.", virtualPorts.isEmpty());
    // Add/remove the virtual port again.
    VirtualPort virtualPort = manager.createVirtualPort(virtualNetwork1.id(), virtualDevice.id(), PortNumber.portNumber(1), cp);
    expectedEventTypes.add(VirtualNetworkEvent.Type.VIRTUAL_PORT_ADDED);
    ConnectPoint newCp = new ConnectPoint(DID2, PortNumber.portNumber(2));
    manager.bindVirtualPort(virtualNetwork1.id(), virtualDevice.id(), PortNumber.portNumber(1), newCp);
    expectedEventTypes.add(VirtualNetworkEvent.Type.VIRTUAL_PORT_UPDATED);
    manager.removeVirtualPort(virtualNetwork1.id(), (DeviceId) virtualPort.element().id(), virtualPort.number());
    expectedEventTypes.add(VirtualNetworkEvent.Type.VIRTUAL_PORT_REMOVED);
    virtualPorts = manager.getVirtualPorts(virtualNetwork1.id(), virtualDevice.id());
    assertTrue("The virtual port set should be empty.", virtualPorts.isEmpty());
    // Validate that the events were all received in the correct order.
    validateEvents(expectedEventTypes.toArray(new VirtualNetworkEvent.Type[expectedEventTypes.size()]));
}
Also used : DefaultVirtualNetwork(org.onosproject.incubator.net.virtual.DefaultVirtualNetwork) VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) ArrayList(java.util.ArrayList) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) ConnectPoint(org.onosproject.net.ConnectPoint) Test(org.junit.Test)

Example 9 with VirtualPort

use of org.onosproject.incubator.net.virtual.VirtualPort in project onos by opennetworkinglab.

the class DistributedVirtualNetworkStore method bindPort.

@Override
public void bindPort(NetworkId networkId, DeviceId deviceId, PortNumber portNumber, ConnectPoint realizedBy) {
    Set<VirtualPort> virtualPortSet = networkIdVirtualPortSetMap.get(networkId);
    Optional<VirtualPort> virtualPortOptional = virtualPortSet.stream().filter(p -> p.element().id().equals(deviceId) && p.number().equals(portNumber)).findFirst();
    checkState(virtualPortOptional.isPresent(), "The virtual port has not been added.");
    VirtualDevice device = deviceIdVirtualDeviceMap.get(new VirtualDeviceId(networkId, deviceId));
    checkNotNull(device, "The device has not been created for deviceId: " + deviceId);
    VirtualPort vPort = virtualPortOptional.get();
    virtualPortSet.remove(vPort);
    vPort = new DefaultVirtualPort(networkId, device, portNumber, realizedBy);
    virtualPortSet.add(vPort);
    networkIdVirtualPortSetMap.put(networkId, virtualPortSet);
    notifyDelegate(new VirtualNetworkEvent(VirtualNetworkEvent.Type.VIRTUAL_PORT_UPDATED, networkId, device, vPort));
}
Also used : VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) DefaultVirtualPort(org.onosproject.incubator.net.virtual.DefaultVirtualPort) ConsistentMap(org.onosproject.store.service.ConsistentMap) HostLocation(org.onosproject.net.HostLocation) CoreService(org.onosproject.core.CoreService) BiFunction(java.util.function.BiFunction) PortNumber(org.onosproject.net.PortNumber) TunnelId(org.onosproject.incubator.net.tunnel.TunnelId) Link(org.onosproject.net.Link) ConnectPoint(org.onosproject.net.ConnectPoint) StorageService(org.onosproject.store.service.StorageService) Map(java.util.Map) VirtualNetworkService(org.onosproject.incubator.net.virtual.VirtualNetworkService) DefaultVirtualHost(org.onosproject.incubator.net.virtual.DefaultVirtualHost) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) Serializer(org.onosproject.store.service.Serializer) ImmutableSet(com.google.common.collect.ImmutableSet) Device(org.onosproject.net.Device) Deactivate(org.osgi.service.component.annotations.Deactivate) IdGenerator(org.onosproject.core.IdGenerator) Set(java.util.Set) WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) Sets(com.google.common.collect.Sets) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Objects(java.util.Objects) Key(org.onosproject.net.intent.Key) VirtualNetworkStoreDelegate(org.onosproject.incubator.net.virtual.VirtualNetworkStoreDelegate) DefaultVirtualLink(org.onosproject.incubator.net.virtual.DefaultVirtualLink) VirtualLink(org.onosproject.incubator.net.virtual.VirtualLink) VirtualNetworkIntent(org.onosproject.incubator.net.virtual.VirtualNetworkIntent) Optional(java.util.Optional) DefaultVirtualDevice(org.onosproject.incubator.net.virtual.DefaultVirtualDevice) DeviceId(org.onosproject.net.DeviceId) VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) DefaultVirtualPort(org.onosproject.incubator.net.virtual.DefaultVirtualPort) VirtualHost(org.onosproject.incubator.net.virtual.VirtualHost) VirtualNetworkEvent(org.onosproject.incubator.net.virtual.VirtualNetworkEvent) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) KryoNamespace(org.onlab.util.KryoNamespace) VirtualNetworkStore(org.onosproject.incubator.net.virtual.VirtualNetworkStore) MapEventListener(org.onosproject.store.service.MapEventListener) HashSet(java.util.HashSet) Component(org.osgi.service.component.annotations.Component) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) Intent(org.onosproject.net.intent.Intent) Activate(org.osgi.service.component.annotations.Activate) HostId(org.onosproject.net.HostId) IpAddress(org.onlab.packet.IpAddress) TenantId(org.onosproject.net.TenantId) Logger(org.slf4j.Logger) SetEvent(org.onosproject.store.service.SetEvent) VlanId(org.onlab.packet.VlanId) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) SetEventListener(org.onosproject.store.service.SetEventListener) DefaultVirtualNetwork(org.onosproject.incubator.net.virtual.DefaultVirtualNetwork) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) DistributedSet(org.onosproject.store.service.DistributedSet) MapEvent(org.onosproject.store.service.MapEvent) AbstractStore(org.onosproject.store.AbstractStore) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) MacAddress(org.onlab.packet.MacAddress) Reference(org.osgi.service.component.annotations.Reference) VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) DefaultVirtualDevice(org.onosproject.incubator.net.virtual.DefaultVirtualDevice) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) VirtualNetworkEvent(org.onosproject.incubator.net.virtual.VirtualNetworkEvent) DefaultVirtualPort(org.onosproject.incubator.net.virtual.DefaultVirtualPort)

Example 10 with VirtualPort

use of org.onosproject.incubator.net.virtual.VirtualPort in project onos by opennetworkinglab.

the class DefaultVirtualPacketProvider method virtualize.

/**
 * Translate the requested physical PacketContext into a virtual PacketContext.
 * See {@link org.onosproject.net.packet.PacketContext}
 *
 * @param context A physical PacketContext be translated
 * @return A translated virtual PacketContext
 */
private VirtualPacketContext virtualize(PacketContext context) {
    VirtualPort vPort = getMappedVirtualPort(context.inPacket().receivedFrom());
    if (vPort != null) {
        ConnectPoint cp = new ConnectPoint(vPort.element().id(), vPort.number());
        Ethernet eth = context.inPacket().parsed();
        eth.setVlanID(Ethernet.VLAN_UNTAGGED);
        InboundPacket inPacket = new DefaultInboundPacket(cp, eth, ByteBuffer.wrap(eth.serialize()));
        DefaultOutboundPacket outPkt = new DefaultOutboundPacket(cp.deviceId(), DefaultTrafficTreatment.builder().build(), ByteBuffer.wrap(eth.serialize()));
        VirtualPacketContext vContext = new DefaultVirtualPacketContext(context.time(), inPacket, outPkt, false, vPort.networkId(), this);
        return vContext;
    } else {
        return null;
    }
}
Also used : VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) Ethernet(org.onlab.packet.Ethernet) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) InboundPacket(org.onosproject.net.packet.InboundPacket) VirtualPacketContext(org.onosproject.incubator.net.virtual.VirtualPacketContext) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) ConnectPoint(org.onosproject.net.ConnectPoint)

Aggregations

VirtualPort (org.onosproject.incubator.net.virtual.VirtualPort)23 ConnectPoint (org.onosproject.net.ConnectPoint)15 VirtualDevice (org.onosproject.incubator.net.virtual.VirtualDevice)11 HashSet (java.util.HashSet)9 VirtualNetwork (org.onosproject.incubator.net.virtual.VirtualNetwork)9 NetworkId (org.onosproject.incubator.net.virtual.NetworkId)8 VirtualNetworkService (org.onosproject.incubator.net.virtual.VirtualNetworkService)8 DeviceId (org.onosproject.net.DeviceId)7 PortNumber (org.onosproject.net.PortNumber)7 Sets (com.google.common.collect.Sets)6 Optional (java.util.Optional)6 Set (java.util.Set)6 CoreService (org.onosproject.core.CoreService)6 VirtualNetworkEvent (org.onosproject.incubator.net.virtual.VirtualNetworkEvent)6 Activate (org.osgi.service.component.annotations.Activate)6 Component (org.osgi.service.component.annotations.Component)6 Deactivate (org.osgi.service.component.annotations.Deactivate)6 Reference (org.osgi.service.component.annotations.Reference)6 ReferenceCardinality (org.osgi.service.component.annotations.ReferenceCardinality)6 Logger (org.slf4j.Logger)6