Search in sources :

Example 1 with VirtualPort

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

the class DefaultVirtualFlowRuleProvider method extractEgressPoints.

/**
 * Extract egress connect point of the physical network
 * from the requested traffic treatment.
 *
 * @param networkId the virtual network identifier
 * @param deviceId the virtual device identifier
 * @param treatment the traffic treatment to extract ingress point
 * @return the egress connect point of the physical network
 */
private ConnectPoint extractEgressPoints(NetworkId networkId, DeviceId deviceId, TrafficTreatment treatment) {
    Set<VirtualPort> vPorts = vnService.getVirtualPorts(networkId, deviceId);
    PortNumber vOutPortNum = treatment.allInstructions().stream().filter(i -> i.type() == Instruction.Type.OUTPUT).map(i -> ((Instructions.OutputInstruction) i).port()).findFirst().get();
    Optional<ConnectPoint> optionalCpOut = vPorts.stream().filter(v -> v.number().equals(vOutPortNum)).map(VirtualPort::realizedBy).findFirst();
    if (!optionalCpOut.isPresent()) {
        if (vOutPortNum.isLogical()) {
            return new ConnectPoint(DeviceId.deviceId("vNet"), vOutPortNum);
        }
        log.warn("Port {} is not realized yet, in Network {}, Device {}", vOutPortNum, networkId, deviceId);
        return null;
    }
    return optionalCpOut.get();
}
Also used : VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) 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) Instructions(org.onosproject.net.flow.instructions.Instructions) PortNumber(org.onosproject.net.PortNumber) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 2 with VirtualPort

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

the class DefaultVirtualFlowRuleProvider method extractIngressPoints.

/**
 * Extract ingress connect points of the physical network
 * from the requested traffic selector.
 *
 * @param networkId the virtual network identifier
 * @param deviceId the virtual device identifier
 * @param selector the traffic selector to extract ingress point
 * @return the set of ingress connect points of the physical network
 */
private Set<ConnectPoint> extractIngressPoints(NetworkId networkId, DeviceId deviceId, TrafficSelector selector) {
    Set<ConnectPoint> ingressPoints = new HashSet<>();
    Set<VirtualPort> vPorts = vnService.getVirtualPorts(networkId, deviceId);
    PortCriterion portCriterion = ((PortCriterion) selector.getCriterion(Criterion.Type.IN_PORT));
    if (portCriterion != null) {
        PortNumber vInPortNum = portCriterion.port();
        Optional<ConnectPoint> optionalCp = vPorts.stream().filter(v -> v.number().equals(vInPortNum)).map(VirtualPort::realizedBy).findFirst();
        if (!optionalCp.isPresent()) {
            log.warn("Port {} is not realized yet, in Network {}, Device {}", vInPortNum, networkId, deviceId);
            return ingressPoints;
        }
        ingressPoints.add(optionalCp.get());
    } else {
        for (VirtualPort vPort : vPorts) {
            if (vPort.realizedBy() != null) {
                ingressPoints.add(vPort.realizedBy());
            } else {
                log.warn("Port {} is not realized yet, in Network {}, " + "Device {}", vPort, networkId, deviceId);
            }
        }
    }
    return ingressPoints;
}
Also used : VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) PortNumber(org.onosproject.net.PortNumber) ConnectPoint(org.onosproject.net.ConnectPoint) HashSet(java.util.HashSet)

Example 3 with VirtualPort

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

the class VirtualPortCompleter method getSortedVirtualPorts.

/**
 * Returns the list of virtual ports sorted using the port number.
 *
 * @param networkId network id.
 * @param deviceId device id
 * @return sorted virtual port list
 */
private List<VirtualPort> getSortedVirtualPorts(long networkId, String deviceId) {
    VirtualNetworkService service = getService(VirtualNetworkService.class);
    List<VirtualPort> virtualPorts = new ArrayList<>();
    virtualPorts.addAll(service.getVirtualPorts(NetworkId.networkId(networkId), DeviceId.deviceId(deviceId)));
    Collections.sort(virtualPorts, Comparators.VIRTUAL_PORT_COMPARATOR);
    return virtualPorts;
}
Also used : VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) VirtualNetworkService(org.onosproject.incubator.net.virtual.VirtualNetworkService) ArrayList(java.util.ArrayList)

Example 4 with VirtualPort

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

the class VirtualPortListCommand method getSortedVirtualPorts.

/**
 * Returns the list of virtual ports sorted using the network identifier.
 *
 * @return sorted virtual port list
 */
private List<VirtualPort> getSortedVirtualPorts() {
    VirtualNetworkService service = get(VirtualNetworkService.class);
    List<VirtualPort> virtualPorts = new ArrayList<>();
    virtualPorts.addAll(service.getVirtualPorts(NetworkId.networkId(networkId), DeviceId.deviceId(deviceId)));
    Collections.sort(virtualPorts, Comparators.VIRTUAL_PORT_COMPARATOR);
    return virtualPorts;
}
Also used : VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) VirtualNetworkService(org.onosproject.incubator.net.virtual.VirtualNetworkService) ArrayList(java.util.ArrayList)

Example 5 with VirtualPort

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

the class VirtualPortStateCommand method doExecute.

@Override
protected void doExecute() {
    VirtualNetworkAdminService service = get(VirtualNetworkAdminService.class);
    VirtualPort vPort = getVirtualPort(PortNumber.portNumber(portNum));
    checkNotNull(vPort, "The virtual Port does not exist");
    boolean isEnabled;
    if ("enable".equals(portState)) {
        isEnabled = true;
    } else if ("disable".equals(portState)) {
        isEnabled = false;
    } else {
        print("State must be enable or disable");
        return;
    }
    service.updatePortState(NetworkId.networkId(networkId), DeviceId.deviceId(deviceId), vPort.number(), isEnabled);
    print("Virtual port state updated.");
}
Also used : VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) VirtualNetworkAdminService(org.onosproject.incubator.net.virtual.VirtualNetworkAdminService)

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