Search in sources :

Example 26 with NetworkId

use of org.onosproject.incubator.net.virtual.NetworkId 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 27 with NetworkId

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

the class DefaultVirtualMeterProvider method activate.

@Activate
public void activate() {
    providerRegistryService.registerProvider(this);
    internalMeterListener = new InternalMeterListener();
    idGenerator = getIdGenerator();
    pendingOperations = CacheBuilder.newBuilder().expireAfterWrite(TIMEOUT, TimeUnit.SECONDS).removalListener((RemovalNotification<Long, VirtualMeterOperation> notification) -> {
        if (notification.getCause() == RemovalCause.EXPIRED) {
            NetworkId networkId = notification.getValue().networkId();
            MeterOperation op = notification.getValue().operation();
            VirtualMeterProviderService providerService = (VirtualMeterProviderService) providerRegistryService.getProviderService(networkId, VirtualMeterProvider.class);
            providerService.meterOperationFailed(op, MeterFailReason.TIMEOUT);
        }
    }).build();
    meterService.addListener(internalMeterListener);
    log.info("Started");
}
Also used : VirtualMeterProvider(org.onosproject.incubator.net.virtual.provider.VirtualMeterProvider) VirtualMeterProviderService(org.onosproject.incubator.net.virtual.provider.VirtualMeterProviderService) RemovalNotification(com.google.common.cache.RemovalNotification) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) MeterOperation(org.onosproject.net.meter.MeterOperation) Activate(org.osgi.service.component.annotations.Activate)

Example 28 with NetworkId

use of org.onosproject.incubator.net.virtual.NetworkId 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 29 with NetworkId

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

the class VirtualHostCodec method decode.

@Override
public VirtualHost decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    NetworkId nId = NetworkId.networkId(Long.parseLong(extractMember(NETWORK_ID, json)));
    MacAddress mac = MacAddress.valueOf(json.get("mac").asText());
    VlanId vlanId = VlanId.vlanId((short) json.get("vlan").asInt(VlanId.UNTAGGED));
    Set<HostLocation> locations = new HashSet<>();
    JsonNode locationNodes = json.get("locations");
    locationNodes.forEach(locationNode -> {
        PortNumber portNumber = PortNumber.portNumber(locationNode.get("port").asText());
        DeviceId deviceId = DeviceId.deviceId(locationNode.get("elementId").asText());
        locations.add(new HostLocation(deviceId, portNumber, 0));
    });
    HostId id = HostId.hostId(mac, vlanId);
    Iterator<JsonNode> ipStrings = json.get("ipAddresses").elements();
    Set<IpAddress> ips = new HashSet<>();
    while (ipStrings.hasNext()) {
        ips.add(IpAddress.valueOf(ipStrings.next().asText()));
    }
    return new DefaultVirtualHost(nId, id, mac, vlanId, locations, ips);
}
Also used : DefaultVirtualHost(org.onosproject.incubator.net.virtual.DefaultVirtualHost) DeviceId(org.onosproject.net.DeviceId) JsonNode(com.fasterxml.jackson.databind.JsonNode) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) MacAddress(org.onlab.packet.MacAddress) HostId(org.onosproject.net.HostId) HostLocation(org.onosproject.net.HostLocation) IpAddress(org.onlab.packet.IpAddress) PortNumber(org.onosproject.net.PortNumber) VlanId(org.onlab.packet.VlanId) HashSet(java.util.HashSet)

Example 30 with NetworkId

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

the class VirtualNetworkCodec method decode.

@Override
public VirtualNetwork decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    NetworkId nId = NetworkId.networkId(Long.parseLong(extractMember(NETWORK_ID, json)));
    TenantId tId = TenantId.tenantId(extractMember(TENANT_ID, json));
    return new DefaultVirtualNetwork(nId, tId);
}
Also used : TenantId(org.onosproject.net.TenantId) DefaultVirtualNetwork(org.onosproject.incubator.net.virtual.DefaultVirtualNetwork) NetworkId(org.onosproject.incubator.net.virtual.NetworkId)

Aggregations

NetworkId (org.onosproject.incubator.net.virtual.NetworkId)50 DeviceId (org.onosproject.net.DeviceId)23 Test (org.junit.Test)21 WebTarget (javax.ws.rs.client.WebTarget)20 Matchers.containsString (org.hamcrest.Matchers.containsString)20 HostResourceTest (org.onosproject.rest.resources.HostResourceTest)20 LinksResourceTest (org.onosproject.rest.resources.LinksResourceTest)20 ResourceTest (org.onosproject.rest.resources.ResourceTest)20 Activate (org.osgi.service.component.annotations.Activate)11 Logger (org.slf4j.Logger)11 LoggerFactory.getLogger (org.slf4j.LoggerFactory.getLogger)11 Set (java.util.Set)10 Component (org.osgi.service.component.annotations.Component)10 Deactivate (org.osgi.service.component.annotations.Deactivate)10 HashSet (java.util.HashSet)9 VirtualDevice (org.onosproject.incubator.net.virtual.VirtualDevice)9 ConnectPoint (org.onosproject.net.ConnectPoint)9 PortNumber (org.onosproject.net.PortNumber)9 Reference (org.osgi.service.component.annotations.Reference)9 ReferenceCardinality (org.osgi.service.component.annotations.ReferenceCardinality)9