Search in sources :

Example 81 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 82 with MacAddress

use of org.onlab.packet.MacAddress in project onos by opennetworkinglab.

the class ReactiveForwarding method findSrcDstPairs.

// Returns a set of src/dst MAC pairs extracted from the specified set of flow entries
private Set<SrcDstPair> findSrcDstPairs(Set<FlowEntry> rules) {
    ImmutableSet.Builder<SrcDstPair> builder = ImmutableSet.builder();
    for (FlowEntry r : rules) {
        MacAddress src = null, dst = null;
        for (Criterion cr : r.selector().criteria()) {
            if (cr.type() == Criterion.Type.ETH_DST) {
                dst = ((EthCriterion) cr).mac();
            } else if (cr.type() == Criterion.Type.ETH_SRC) {
                src = ((EthCriterion) cr).mac();
            }
        }
        builder.add(new SrcDstPair(src, dst));
    }
    return builder.build();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) MacAddress(org.onlab.packet.MacAddress) FlowEntry(org.onosproject.net.flow.FlowEntry)

Example 83 with MacAddress

use of org.onlab.packet.MacAddress in project onos by opennetworkinglab.

the class ReactiveForwarding method printMetric.

public void printMetric(MacAddress mac) {
    System.out.println("-----------------------------------------------------------------------------------------");
    System.out.println(" MACADDRESS \t\t\t\t\t\t Metrics");
    if (mac != null) {
        System.out.println(" " + mac + " \t\t\t " + metrics.get(mac));
    } else {
        for (MacAddress key : metrics.keySet()) {
            System.out.println(" " + key + " \t\t\t " + metrics.get(key));
        }
    }
}
Also used : MacAddress(org.onlab.packet.MacAddress)

Example 84 with MacAddress

use of org.onlab.packet.MacAddress 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 85 with MacAddress

use of org.onlab.packet.MacAddress in project onos by opennetworkinglab.

the class InterfaceConfig method getInterfaces.

/**
 * Retrieves all interfaces configured on this port.
 *
 * @return set of interfaces
 * @throws ConfigException if there is any error in the JSON config
 */
public Set<Interface> getInterfaces() throws ConfigException {
    Set<Interface> interfaces = Sets.newHashSet();
    try {
        for (JsonNode intfNode : array) {
            String name = intfNode.path(NAME).asText(null);
            List<InterfaceIpAddress> ips = getIps(intfNode);
            String mac = intfNode.path(MAC).asText();
            MacAddress macAddr = mac.isEmpty() ? null : MacAddress.valueOf(mac);
            VlanId vlan = getVlan(intfNode, VLAN);
            VlanId vlanUntagged = getVlan(intfNode, VLAN_UNTAGGED);
            Set<VlanId> vlanTagged = getVlans(intfNode, VLAN_TAGGED);
            VlanId vlanNative = getVlan(intfNode, VLAN_NATIVE);
            interfaces.add(new Interface(name, subject, ips, macAddr, vlan, vlanUntagged, vlanTagged, vlanNative));
        }
    } catch (IllegalArgumentException e) {
        throw new ConfigException(CONFIG_VALUE_ERROR, e);
    }
    return interfaces;
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ConfigException(org.onosproject.net.config.ConfigException) MacAddress(org.onlab.packet.MacAddress) Interface(org.onosproject.net.intf.Interface) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) VlanId(org.onlab.packet.VlanId)

Aggregations

MacAddress (org.onlab.packet.MacAddress)171 VlanId (org.onlab.packet.VlanId)66 IpAddress (org.onlab.packet.IpAddress)63 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)43 Host (org.onosproject.net.Host)38 TrafficSelector (org.onosproject.net.flow.TrafficSelector)37 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)36 Set (java.util.Set)33 HostLocation (org.onosproject.net.HostLocation)32 Ethernet (org.onlab.packet.Ethernet)31 Logger (org.slf4j.Logger)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