Search in sources :

Example 16 with VirtualPort

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

the class VirtualPortStateCommand method getVirtualPort.

/**
 * Returns the virtual port matching the device and port identifier.
 *
 * @param aPortNumber port identifier
 * @return matching virtual port, or null.
 */
private VirtualPort getVirtualPort(PortNumber aPortNumber) {
    VirtualNetworkService service = get(VirtualNetworkService.class);
    Set<VirtualPort> ports = service.getVirtualPorts(NetworkId.networkId(networkId), DeviceId.deviceId(deviceId));
    return ports.stream().filter(p -> p.number().equals(aPortNumber)).findFirst().get();
}
Also used : VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) VirtualNetworkService(org.onosproject.incubator.net.virtual.VirtualNetworkService)

Example 17 with VirtualPort

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

the class DistributedVirtualNetworkStore method addPort.

@Override
public VirtualPort addPort(NetworkId networkId, DeviceId deviceId, PortNumber portNumber, ConnectPoint realizedBy) {
    checkState(networkExists(networkId), "The network has not been added.");
    Set<VirtualPort> virtualPortSet = networkIdVirtualPortSetMap.get(networkId);
    if (virtualPortSet == null) {
        virtualPortSet = new HashSet<>();
    }
    VirtualDevice device = deviceIdVirtualDeviceMap.get(new VirtualDeviceId(networkId, deviceId));
    checkNotNull(device, "The device has not been created for deviceId: " + deviceId);
    checkState(!virtualPortExists(networkId, deviceId, portNumber), "The requested Port Number has been added.");
    VirtualPort virtualPort = new DefaultVirtualPort(networkId, device, portNumber, realizedBy);
    virtualPortSet.add(virtualPort);
    networkIdVirtualPortSetMap.put(networkId, virtualPortSet);
    notifyDelegate(new VirtualNetworkEvent(VirtualNetworkEvent.Type.VIRTUAL_PORT_ADDED, networkId, device, virtualPort));
    return virtualPort;
}
Also used : VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) DefaultVirtualPort(org.onosproject.incubator.net.virtual.DefaultVirtualPort) 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 18 with VirtualPort

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

the class DistributedVirtualNetworkStore method updatePortState.

@Override
public void updatePortState(NetworkId networkId, DeviceId deviceId, PortNumber portNumber, boolean isEnabled) {
    checkState(networkExists(networkId), "No network with NetworkId %s exists.", networkId);
    VirtualDevice device = deviceIdVirtualDeviceMap.get(new VirtualDeviceId(networkId, deviceId));
    checkNotNull(device, "No device %s exists in NetworkId: %s", deviceId, networkId);
    Set<VirtualPort> virtualPortSet = networkIdVirtualPortSetMap.get(networkId);
    checkNotNull(virtualPortSet, "No port has been created for NetworkId: %s", 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.");
    VirtualPort oldPort = virtualPortOptional.get();
    if (oldPort.isEnabled() == isEnabled) {
        log.debug("No change in port state - port not updated");
        return;
    }
    VirtualPort newPort = new DefaultVirtualPort(networkId, device, portNumber, isEnabled, oldPort.realizedBy());
    virtualPortSet.remove(oldPort);
    virtualPortSet.add(newPort);
    networkIdVirtualPortSetMap.put(networkId, virtualPortSet);
    notifyDelegate(new VirtualNetworkEvent(VirtualNetworkEvent.Type.VIRTUAL_PORT_UPDATED, networkId, device, newPort));
    log.debug("port state changed from {} to {}", oldPort.isEnabled(), isEnabled);
}
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 19 with VirtualPort

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

the class DefaultVirtualFlowRuleProvider method devirtualize.

/**
 * Translate the requested virtual flow rules into physical flow rules.
 * The translation could be one to many.
 *
 * @param flowRule A flow rule from underlying data plane to be translated
 * @return A set of flow rules for physical network
 */
private Set<FlowRule> devirtualize(NetworkId networkId, FlowRule flowRule) {
    Set<FlowRule> outRules = new HashSet<>();
    Set<ConnectPoint> ingressPoints = extractIngressPoints(networkId, flowRule.deviceId(), flowRule.selector());
    ConnectPoint egressPoint = extractEgressPoints(networkId, flowRule.deviceId(), flowRule.treatment());
    if (egressPoint == null) {
        return outRules;
    }
    TrafficSelector.Builder commonSelectorBuilder = DefaultTrafficSelector.builder();
    flowRule.selector().criteria().stream().filter(c -> c.type() != Criterion.Type.IN_PORT).forEach(c -> commonSelectorBuilder.add(c));
    TrafficSelector commonSelector = commonSelectorBuilder.build();
    TrafficTreatment.Builder commonTreatmentBuilder = DefaultTrafficTreatment.builder();
    flowRule.treatment().allInstructions().stream().filter(i -> i.type() != Instruction.Type.OUTPUT).forEach(i -> commonTreatmentBuilder.add(i));
    TrafficTreatment commonTreatment = commonTreatmentBuilder.build();
    for (ConnectPoint ingressPoint : ingressPoints) {
        if (egressPoint.port() == PortNumber.FLOOD) {
            Set<ConnectPoint> outPoints = vnService.getVirtualPorts(networkId, flowRule.deviceId()).stream().map(VirtualPort::realizedBy).filter(p -> !p.equals(ingressPoint)).collect(Collectors.toSet());
            for (ConnectPoint outPoint : outPoints) {
                outRules.addAll(generateRules(networkId, ingressPoint, outPoint, commonSelector, commonTreatment, flowRule));
            }
        } else {
            outRules.addAll(generateRules(networkId, ingressPoint, egressPoint, commonSelector, commonTreatment, flowRule));
        }
    }
    return outRules;
}
Also used : DefaultApplicationId(org.onosproject.core.DefaultApplicationId) FlowRuleBatchOperation(org.onosproject.net.flow.oldbatch.FlowRuleBatchOperation) CompletedBatchOperation(org.onosproject.net.flow.CompletedBatchOperation) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) CoreService(org.onosproject.core.CoreService) BatchOperationEntry(org.onosproject.net.flow.BatchOperationEntry) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) FlowEntry(org.onosproject.net.flow.FlowEntry) HashBasedTable(com.google.common.collect.HashBasedTable) InternalRoutingAlgorithm(org.onosproject.incubator.net.virtual.provider.InternalRoutingAlgorithm) TopologyService(org.onosproject.net.topology.TopologyService) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) Link(org.onosproject.net.Link) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) FlowRuleService(org.onosproject.net.flow.FlowRuleService) VirtualFlowRuleProviderService(org.onosproject.incubator.net.virtual.provider.VirtualFlowRuleProviderService) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) VirtualNetworkService(org.onosproject.incubator.net.virtual.VirtualNetworkService) ImmutableSet(com.google.common.collect.ImmutableSet) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) FlowRuleBatchEntry(org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry) FlowRule(org.onosproject.net.flow.FlowRule) Optional(java.util.Optional) Path(org.onosproject.net.Path) DeviceId(org.onosproject.net.DeviceId) VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) Dictionary(java.util.Dictionary) FlowRuleOperationsContext(org.onosproject.net.flow.FlowRuleOperationsContext) VirtualFlowRuleProvider(org.onosproject.incubator.net.virtual.provider.VirtualFlowRuleProvider) FlowRuleEvent(org.onosproject.net.flow.FlowRuleEvent) ComponentContext(org.osgi.service.component.ComponentContext) HashSet(java.util.HashSet) Component(org.osgi.service.component.annotations.Component) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) VirtualProviderRegistryService(org.onosproject.incubator.net.virtual.provider.VirtualProviderRegistryService) Activate(org.osgi.service.component.annotations.Activate) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) FlowRuleListener(org.onosproject.net.flow.FlowRuleListener) Criterion(org.onosproject.net.flow.criteria.Criterion) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) Instructions(org.onosproject.net.flow.instructions.Instructions) Logger(org.slf4j.Logger) ImmutableSet.copyOf(com.google.common.collect.ImmutableSet.copyOf) Instruction(org.onosproject.net.flow.instructions.Instruction) VlanId(org.onlab.packet.VlanId) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) ProviderId(org.onosproject.net.provider.ProviderId) Maps(com.google.common.collect.Maps) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) AbstractVirtualProvider(org.onosproject.incubator.net.virtual.provider.AbstractVirtualProvider) Modified(org.osgi.service.component.annotations.Modified) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Reference(org.osgi.service.component.annotations.Reference) Table(com.google.common.collect.Table) VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) HashSet(java.util.HashSet)

Example 20 with VirtualPort

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

the class DefaultVirtualPacketProvider method devirtualizeContext.

/**
 * Translate the requested virtual packet context into
 * a set of physical outbound packets.
 *
 * @param context A handled virtual packet context
 */
private Set<OutboundPacket> devirtualizeContext(VirtualPacketContext context) {
    Set<OutboundPacket> outboundPackets = new HashSet<>();
    NetworkId networkId = context.networkId();
    TrafficTreatment vTreatment = context.treatmentBuilder().build();
    DeviceId sendThrough = context.outPacket().sendThrough();
    Set<VirtualPort> vPorts = vnaService.getVirtualPorts(networkId, sendThrough);
    PortNumber vOutPortNum = vTreatment.allInstructions().stream().filter(i -> i.type() == Instruction.Type.OUTPUT).map(i -> ((Instructions.OutputInstruction) i).port()).findFirst().get();
    TrafficTreatment.Builder commonTreatmentBuilder = DefaultTrafficTreatment.builder();
    vTreatment.allInstructions().stream().filter(i -> i.type() != Instruction.Type.OUTPUT).forEach(i -> commonTreatmentBuilder.add(i));
    TrafficTreatment commonTreatment = commonTreatmentBuilder.build();
    if (!vOutPortNum.isLogical()) {
        Optional<ConnectPoint> optionalCpOut = vPorts.stream().filter(v -> v.number().equals(vOutPortNum)).map(v -> v.realizedBy()).findFirst();
        if (!optionalCpOut.isPresent()) {
            log.warn("Port {} is not realized yet, in Network {}, Device {}", vOutPortNum, networkId, sendThrough);
            return outboundPackets;
        }
        ConnectPoint egressPoint = optionalCpOut.get();
        TrafficTreatment treatment = DefaultTrafficTreatment.builder(commonTreatment).setOutput(egressPoint.port()).build();
        OutboundPacket outboundPacket = new DefaultOutboundPacket(egressPoint.deviceId(), treatment, context.outPacket().data());
        outboundPackets.add(outboundPacket);
    } else {
        if (vOutPortNum == PortNumber.FLOOD) {
            Set<VirtualPort> outPorts = vPorts.stream().filter(vp -> !vp.number().isLogical()).filter(vp -> vp.number() != context.inPacket().receivedFrom().port()).collect(Collectors.toSet());
            for (VirtualPort outPort : outPorts) {
                ConnectPoint cpOut = outPort.realizedBy();
                if (cpOut != null) {
                    TrafficTreatment treatment = DefaultTrafficTreatment.builder(commonTreatment).setOutput(cpOut.port()).build();
                    OutboundPacket outboundPacket = new DefaultOutboundPacket(cpOut.deviceId(), treatment, context.outPacket().data());
                    outboundPackets.add(outboundPacket);
                } else {
                    log.warn("Port {} is not realized yet, in Network {}, Device {}", outPort.number(), networkId, sendThrough);
                }
            }
        }
    }
    return outboundPackets;
}
Also used : VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) VirtualNetworkEvent(org.onosproject.incubator.net.virtual.VirtualNetworkEvent) CoreService(org.onosproject.core.CoreService) PortNumber(org.onosproject.net.PortNumber) ComponentContext(org.osgi.service.component.ComponentContext) VirtualPacketProviderService(org.onosproject.incubator.net.virtual.provider.VirtualPacketProviderService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ByteBuffer(java.nio.ByteBuffer) ConnectPoint(org.onosproject.net.ConnectPoint) HashSet(java.util.HashSet) Ethernet(org.onlab.packet.Ethernet) Component(org.osgi.service.component.annotations.Component) VirtualPacketContext(org.onosproject.incubator.net.virtual.VirtualPacketContext) OutboundPacket(org.onosproject.net.packet.OutboundPacket) ApplicationId(org.onosproject.core.ApplicationId) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) Activate(org.osgi.service.component.annotations.Activate) VirtualProviderRegistryService(org.onosproject.incubator.net.virtual.provider.VirtualProviderRegistryService) TenantId(org.onosproject.net.TenantId) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Instructions(org.onosproject.net.flow.instructions.Instructions) Logger(org.slf4j.Logger) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) Deactivate(org.osgi.service.component.annotations.Deactivate) Instruction(org.onosproject.net.flow.instructions.Instruction) PacketProcessor(org.onosproject.net.packet.PacketProcessor) Set(java.util.Set) PacketService(org.onosproject.net.packet.PacketService) ProviderId(org.onosproject.net.provider.ProviderId) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) VirtualPacketProvider(org.onosproject.incubator.net.virtual.provider.VirtualPacketProvider) VirtualNetworkListener(org.onosproject.incubator.net.virtual.VirtualNetworkListener) AbstractVirtualProvider(org.onosproject.incubator.net.virtual.provider.AbstractVirtualProvider) InboundPacket(org.onosproject.net.packet.InboundPacket) PacketContext(org.onosproject.net.packet.PacketContext) Modified(org.osgi.service.component.annotations.Modified) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) VirtualNetworkAdminService(org.onosproject.incubator.net.virtual.VirtualNetworkAdminService) Optional(java.util.Optional) PacketPriority(org.onosproject.net.packet.PacketPriority) Reference(org.osgi.service.component.annotations.Reference) DeviceId(org.onosproject.net.DeviceId) VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) Dictionary(java.util.Dictionary) DeviceId(org.onosproject.net.DeviceId) Instructions(org.onosproject.net.flow.instructions.Instructions) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) OutboundPacket(org.onosproject.net.packet.OutboundPacket) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) PortNumber(org.onosproject.net.PortNumber) HashSet(java.util.HashSet)

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