Search in sources :

Example 16 with MacAddress

use of org.onlab.packet.MacAddress in project trellis-control by opennetworkinglab.

the class McastUtils method getRouterMac.

/**
 * Get router mac using application config and the connect point.
 *
 * @param deviceId the device id
 * @param port the port number
 * @return the router mac if the port is configured, otherwise null
 */
private MacAddress getRouterMac(DeviceId deviceId, PortNumber port) {
    // Do nothing if the port is configured as suppressed
    ConnectPoint connectPoint = new ConnectPoint(deviceId, port);
    SegmentRoutingAppConfig appConfig = srManager.cfgService.getConfig(srManager.appId(), SegmentRoutingAppConfig.class);
    if (appConfig != null && appConfig.suppressSubnet().contains(connectPoint)) {
        log.info("Ignore suppressed port {}", connectPoint);
        return MacAddress.NONE;
    }
    // Get the router mac using the device configuration
    MacAddress routerMac;
    try {
        routerMac = srManager.deviceConfiguration().getDeviceMac(deviceId);
    } catch (DeviceConfigNotFoundException dcnfe) {
        log.warn("Failed to get device MAC since the device {} is not configured", deviceId);
        return null;
    }
    return routerMac;
}
Also used : SegmentRoutingAppConfig(org.onosproject.segmentrouting.config.SegmentRoutingAppConfig) MacAddress(org.onlab.packet.MacAddress) ConnectPoint(org.onosproject.net.ConnectPoint) DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException)

Example 17 with MacAddress

use of org.onlab.packet.MacAddress in project trellis-control by opennetworkinglab.

the class MockFlowObjectiveService method forward.

@Override
public void forward(DeviceId deviceId, ForwardingObjective forwardingObjective) {
    TrafficSelector selector = forwardingObjective.selector();
    TrafficTreatment treatment = nextTable.get(forwardingObjective.nextId());
    MacAddress macAddress = ((EthCriterion) selector.getCriterion(Criterion.Type.ETH_DST)).mac();
    VlanId vlanId = ((VlanIdCriterion) selector.getCriterion(Criterion.Type.VLAN_VID)).vlanId();
    boolean popVlan = treatment.allInstructions().stream().filter(instruction -> instruction.type().equals(Instruction.Type.L2MODIFICATION)).anyMatch(instruction -> ((L2ModificationInstruction) instruction).subtype().equals(L2ModificationInstruction.L2SubType.VLAN_POP));
    PortNumber portNumber = treatment.allInstructions().stream().filter(instruction -> instruction.type().equals(Instruction.Type.OUTPUT)).map(instruction -> ((Instructions.OutputInstruction) instruction).port()).findFirst().orElse(null);
    if (portNumber == null) {
        throw new IllegalArgumentException();
    }
    Objective.Operation op = forwardingObjective.op();
    MockBridgingTableKey btKey = new MockBridgingTableKey(deviceId, macAddress, vlanId);
    MockBridgingTableValue btValue = new MockBridgingTableValue(popVlan, portNumber);
    if (op.equals(Objective.Operation.ADD)) {
        bridgingTable.put(btKey, btValue);
        forwardingObjective.context().ifPresent(context -> context.onSuccess(forwardingObjective));
    } else if (op.equals(Objective.Operation.REMOVE)) {
        bridgingTable.remove(btKey, btValue);
        forwardingObjective.context().ifPresent(context -> context.onSuccess(forwardingObjective));
    } else {
        forwardingObjective.context().ifPresent(context -> context.onError(forwardingObjective, ObjectiveError.UNKNOWN));
        throw new IllegalArgumentException();
    }
}
Also used : TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Instructions(org.onosproject.net.flow.instructions.Instructions) Instruction(org.onosproject.net.flow.instructions.Instruction) VlanId(org.onlab.packet.VlanId) PortNumber(org.onosproject.net.PortNumber) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError) TrafficSelector(org.onosproject.net.flow.TrafficSelector) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) Map(java.util.Map) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) Objective(org.onosproject.net.flowobjective.Objective) MacAddress(org.onlab.packet.MacAddress) DeviceId(org.onosproject.net.DeviceId) FlowObjectiveServiceAdapter(org.onosproject.net.flowobjective.FlowObjectiveServiceAdapter) Criterion(org.onosproject.net.flow.criteria.Criterion) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) Instructions(org.onosproject.net.flow.instructions.Instructions) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) MacAddress(org.onlab.packet.MacAddress) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) Objective(org.onosproject.net.flowobjective.Objective) TrafficSelector(org.onosproject.net.flow.TrafficSelector) PortNumber(org.onosproject.net.PortNumber) VlanId(org.onlab.packet.VlanId) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion)

Example 18 with MacAddress

use of org.onlab.packet.MacAddress in project trellis-control by opennetworkinglab.

the class PolicyManager method redirectPolicyNextObjective.

private NextObjective.Builder redirectPolicyNextObjective(DeviceId srcDevice, RedirectPolicy redirectPolicy) {
    Set<Link> egressLinks = linkService.getDeviceEgressLinks(srcDevice);
    Map<ConnectPoint, DeviceId> egressPortsToEnforce = Maps.newHashMap();
    List<DeviceId> edgeDevices = getEdgeDeviceIds();
    egressLinks.stream().filter(link -> redirectPolicy.spinesToEnforce().contains(link.dst().deviceId()) && !edgeDevices.contains(link.dst().deviceId())).forEach(link -> egressPortsToEnforce.put(link.src(), link.dst().deviceId()));
    // No ports no friend
    if (egressPortsToEnforce.isEmpty()) {
        log.warn("There are no port available for the REDIRECT policy {}", redirectPolicy.policyId());
        return null;
    }
    // We need to add a treatment for each valid egress port. The treatment
    // requires to set src and dst mac address and set the egress port. We are
    // deliberately not providing the metadata to prevent the programming of
    // some tables which are already controlled by SegmentRouting or are unnecessary
    int nextId = flowObjectiveService.allocateNextId();
    DefaultNextObjective.Builder builder = DefaultNextObjective.builder().withId(nextId).withType(NextObjective.Type.HASHED).fromApp(appId);
    MacAddress srcDeviceMac;
    try {
        srcDeviceMac = getDeviceMacAddress(srcDevice);
    } catch (DeviceConfigNotFoundException e) {
        log.warn(e.getMessage() + " Aborting installation REDIRECT policy {}", redirectPolicy.policyId());
        return null;
    }
    MacAddress neigborDeviceMac;
    TrafficTreatment.Builder tBuilder;
    for (Map.Entry<ConnectPoint, DeviceId> entry : egressPortsToEnforce.entrySet()) {
        try {
            neigborDeviceMac = getDeviceMacAddress(entry.getValue());
        } catch (DeviceConfigNotFoundException e) {
            log.warn(e.getMessage() + " Aborting installation REDIRECT policy {}", redirectPolicy.policyId());
            return null;
        }
        tBuilder = DefaultTrafficTreatment.builder().setEthSrc(srcDeviceMac).setEthDst(neigborDeviceMac).setOutput(entry.getKey().port());
        builder.addTreatment(tBuilder.build());
    }
    return builder;
}
Also used : DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException) ConsistentMap(org.onosproject.store.service.ConsistentMap) NetworkConfigRegistry(org.onosproject.net.config.NetworkConfigRegistry) PredictableExecutor(org.onlab.util.PredictableExecutor) CoreService(org.onosproject.core.CoreService) DeviceService(org.onosproject.net.device.DeviceService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) DropPolicy(org.onosproject.segmentrouting.policy.api.DropPolicy) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) Link(org.onosproject.net.Link) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) Sets(org.glassfish.jersey.internal.guava.Sets) StorageService(org.onosproject.store.service.StorageService) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) NextObjective(org.onosproject.net.flowobjective.NextObjective) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) EDGE_PORT(org.onosproject.segmentrouting.metadata.SRObjectiveMetadata.EDGE_PORT) WorkPartitionService(org.onosproject.net.intent.WorkPartitionService) NodeId(org.onosproject.cluster.NodeId) Serializer(org.onosproject.store.service.Serializer) ImmutableSet(com.google.common.collect.ImmutableSet) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) Collectors(java.util.stream.Collectors) TrafficMatchData(org.onosproject.segmentrouting.policy.api.TrafficMatchData) PolicyType(org.onosproject.segmentrouting.policy.api.Policy.PolicyType) Executors(java.util.concurrent.Executors) Versioned(org.onosproject.store.service.Versioned) List(java.util.List) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) Policy(org.onosproject.segmentrouting.policy.api.Policy) TrafficMatchState(org.onosproject.segmentrouting.policy.api.TrafficMatchState) RedirectPolicy(org.onosproject.segmentrouting.policy.api.RedirectPolicy) LinkService(org.onosproject.net.link.LinkService) Optional(java.util.Optional) ClusterService(org.onosproject.cluster.ClusterService) HashFunction(com.google.common.hash.HashFunction) DeviceId(org.onosproject.net.DeviceId) PolicyService(org.onosproject.segmentrouting.policy.api.PolicyService) StorageException(org.onosproject.store.service.StorageException) NetworkConfigEvent(org.onosproject.net.config.NetworkConfigEvent) Hashing(com.google.common.hash.Hashing) SegmentRoutingDeviceConfig(org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig) CompletableFuture(java.util.concurrent.CompletableFuture) PolicyState(org.onosproject.segmentrouting.policy.api.PolicyState) KryoNamespace(org.onlab.util.KryoNamespace) MapEventListener(org.onosproject.store.service.MapEventListener) ArrayList(java.util.ArrayList) FlowObjectiveService(org.onosproject.net.flowobjective.FlowObjectiveService) TrafficMatch(org.onosproject.segmentrouting.policy.api.TrafficMatch) Component(org.osgi.service.component.annotations.Component) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) Activate(org.osgi.service.component.annotations.Activate) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) ExecutorService(java.util.concurrent.ExecutorService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Logger(org.slf4j.Logger) TrafficMatchPriority(org.onosproject.segmentrouting.policy.api.TrafficMatchPriority) Maps(com.google.common.collect.Maps) CodecService(org.onosproject.codec.CodecService) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) PolicyId(org.onosproject.segmentrouting.policy.api.PolicyId) TrafficMatchId(org.onosproject.segmentrouting.policy.api.TrafficMatchId) MapEvent(org.onosproject.store.service.MapEvent) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Objective(org.onosproject.net.flowobjective.Objective) MacAddress(org.onlab.packet.MacAddress) Reference(org.osgi.service.component.annotations.Reference) NetworkConfigListener(org.onosproject.net.config.NetworkConfigListener) PolicyData(org.onosproject.segmentrouting.policy.api.PolicyData) DeviceId(org.onosproject.net.DeviceId) MacAddress(org.onlab.packet.MacAddress) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) ConnectPoint(org.onosproject.net.ConnectPoint) DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) ConsistentMap(org.onosproject.store.service.ConsistentMap) Map(java.util.Map) Link(org.onosproject.net.Link)

Example 19 with MacAddress

use of org.onlab.packet.MacAddress in project trellis-control by opennetworkinglab.

the class DefaultL2TunnelHandler method createNextObjective.

/**
 * Creates the next objective according to a given
 * pipeline. We don't set the next id and we don't
 * create the final meta to check if we are re-using
 * the same next objective for different tunnels.
 *
 * @param pipeline the pipeline to support
 * @param srcCp    the source port
 * @param dstCp    the destination port
 * @param l2Tunnel the tunnel to support
 * @param egressId the egress device id
 * @param oneHop if the pw only has one hop, push only pw label
 * @param termVlanId the outer vlan id of the packet exiting a termination point
 * @return the next objective to support the pipeline
 */
private NextObjective.Builder createNextObjective(Pipeline pipeline, ConnectPoint srcCp, ConnectPoint dstCp, L2Tunnel l2Tunnel, DeviceId egressId, boolean oneHop, VlanId termVlanId) {
    log.debug("Creating {} next objective for pseudowire {}.", pipeline == TERMINATION ? "termination" : "inititation");
    NextObjective.Builder nextObjBuilder;
    TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
    if (pipeline == INITIATION) {
        nextObjBuilder = DefaultNextObjective.builder().withType(NextObjective.Type.SIMPLE).fromApp(srManager.appId());
        // be different -1.
        if (l2Tunnel.pwLabel().toInt() == MplsLabel.MAX_MPLS) {
            log.error("Pw label not configured");
            return null;
        }
        treatmentBuilder.pushMpls();
        treatmentBuilder.setMpls(l2Tunnel.pwLabel());
        treatmentBuilder.setMplsBos(true);
        treatmentBuilder.copyTtlOut();
        // If the inter-co label is present we have to set the label.
        if (l2Tunnel.interCoLabel().toInt() != MplsLabel.MAX_MPLS) {
            treatmentBuilder.pushMpls();
            treatmentBuilder.setMpls(l2Tunnel.interCoLabel());
            treatmentBuilder.setMplsBos(false);
            treatmentBuilder.copyTtlOut();
        }
        // if not oneHop install transit mpls labels also
        if (!oneHop) {
            // We retrieve the sr label from the config
            // specific for pseudowire traffic
            // using the egress leaf device id.
            MplsLabel srLabel;
            try {
                srLabel = MplsLabel.mplsLabel(srManager.deviceConfiguration().getPWRoutingLabel(egressId));
            } catch (DeviceConfigNotFoundException e) {
                log.error("Sr label for pw traffic not configured");
                return null;
            }
            treatmentBuilder.pushMpls();
            treatmentBuilder.setMpls(srLabel);
            treatmentBuilder.setMplsBos(false);
            treatmentBuilder.copyTtlOut();
        }
        // We have to rewrite the src and dst mac address.
        MacAddress ingressMac;
        try {
            ingressMac = srManager.deviceConfiguration().getDeviceMac(srcCp.deviceId());
        } catch (DeviceConfigNotFoundException e) {
            log.error("Was not able to find the ingress mac");
            return null;
        }
        treatmentBuilder.setEthSrc(ingressMac);
        MacAddress neighborMac;
        try {
            neighborMac = srManager.deviceConfiguration().getDeviceMac(dstCp.deviceId());
        } catch (DeviceConfigNotFoundException e) {
            log.error("Was not able to find the neighbor mac");
            return null;
        }
        treatmentBuilder.setEthDst(neighborMac);
        // set the appropriate transport vlan from tunnel information
        treatmentBuilder.setVlanId(l2Tunnel.transportVlan());
    } else {
        // We create the next objective which
        // will be a simple l2 group.
        nextObjBuilder = DefaultNextObjective.builder().withType(NextObjective.Type.SIMPLE).fromApp(srManager.appId());
        // for termination point we use the outer vlan of the
        // encapsulated packet for the vlan
        treatmentBuilder.setVlanId(termVlanId);
    }
    treatmentBuilder.setOutput(srcCp.port());
    nextObjBuilder.addTreatment(treatmentBuilder.build());
    return nextObjBuilder;
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) MplsLabel(org.onlab.packet.MplsLabel) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) MacAddress(org.onlab.packet.MacAddress) DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException)

Example 20 with MacAddress

use of org.onlab.packet.MacAddress in project TFG by mattinelorza.

the class Ipv6RoutingComponent method createNextHopGroup.

/**
 * Creates an ONOS SELECT group for the routing table to provide ECMP
 * forwarding for the given collection of next hop MAC addresses. ONOS
 * SELECT groups are equivalent to P4Runtime action selector groups.
 * <p>
 * This method will be called by the routing policy methods below to insert
 * groups in the L3 table
 *
 * @param nextHopMacs the collection of mac addresses of next hops
 * @param deviceId    the device where the group will be installed
 * @return a SELECT group
 */
private GroupDescription createNextHopGroup(int groupId, Collection<MacAddress> nextHopMacs, DeviceId deviceId) {
    String actionProfileId = "IngressPipeImpl.ecmp_selector";
    final List<PiAction> actions = Lists.newArrayList();
    // Build one "set next hop" action for each next hop
    // *** TODO EXERCISE 5
    // Modify P4Runtime entity names to match content of P4Info file (look
    // for the fully qualified name of tables, match fields, and actions.
    // ---- START SOLUTION ----
    final String tableId = "IngressPipeImpl.routing_v6_table";
    for (MacAddress nextHopMac : nextHopMacs) {
        final PiAction action = PiAction.builder().withId(PiActionId.of("IngressPipeImpl.set_next_hop")).withParameter(new PiActionParam(// Action param name.
        PiActionParamId.of("dmac"), // Action param value.
        nextHopMac.toBytes())).build();
        actions.add(action);
    }
    return Utils.buildSelectGroup(deviceId, tableId, actionProfileId, groupId, actions, appId);
}
Also used : MacAddress(org.onlab.packet.MacAddress) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) PiAction(org.onosproject.net.pi.runtime.PiAction)

Aggregations

MacAddress (org.onlab.packet.MacAddress)175 VlanId (org.onlab.packet.VlanId)67 IpAddress (org.onlab.packet.IpAddress)65 ConnectPoint (org.onosproject.net.ConnectPoint)55 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)54 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)53 DeviceId (org.onosproject.net.DeviceId)44 TrafficSelector (org.onosproject.net.flow.TrafficSelector)40 Host (org.onosproject.net.Host)38 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)36 Set (java.util.Set)33 HostLocation (org.onosproject.net.HostLocation)32 Logger (org.slf4j.Logger)32 Ethernet (org.onlab.packet.Ethernet)31 PortNumber (org.onosproject.net.PortNumber)29 List (java.util.List)27 HostId (org.onosproject.net.HostId)27 Interface (org.onosproject.net.intf.Interface)27 IpPrefix (org.onlab.packet.IpPrefix)26 LoggerFactory (org.slf4j.LoggerFactory)24