Search in sources :

Example 76 with VlanId

use of org.onlab.packet.VlanId 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 77 with VlanId

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

the class ResourceDeviceListener method registerPortResource.

private void registerPortResource(Device device, Port port) {
    Resource portPath = Resources.discrete(device.id(), port.number()).resource();
    if (!adminService.register(portPath)) {
        log.error("Failed to register Port: {}", portPath.id());
    }
    queryBandwidth(device.id(), port.number()).map(bw -> portPath.child(Bandwidth.class, bw.bps())).map(adminService::register).ifPresent(success -> {
        if (!success) {
            log.error("Failed to register Bandwidth for {}", portPath.id());
        }
    });
    // for VLAN IDs
    Set<VlanId> vlans = queryVlanIds(device.id(), port.number());
    if (!vlans.isEmpty()) {
        boolean success = adminService.register(vlans.stream().map(portPath::child).collect(Collectors.toList()));
        if (!success) {
            log.error("Failed to register VLAN IDs for {}", portPath.id());
        }
    }
    // for MPLS labels
    Set<MplsLabel> mplsLabels = queryMplsLabels(device.id(), port.number());
    if (!mplsLabels.isEmpty()) {
        boolean success = adminService.register(mplsLabels.stream().map(portPath::child).collect(Collectors.toList()));
        if (!success) {
            log.error("Failed to register MPLS Labels for {}", portPath.id());
        }
    }
    // for Lambdas
    Set<OchSignal> lambdas = queryLambdas(device.id(), port.number());
    if (!lambdas.isEmpty()) {
        boolean success = adminService.register(lambdas.stream().map(portPath::child).collect(Collectors.toList()));
        if (!success) {
            log.error("Failed to register lambdas for {}", portPath.id());
        }
    }
    // for Tributary slots
    Set<TributarySlot> tSlots = queryTributarySlots(device.id(), port.number());
    if (!tSlots.isEmpty()) {
        boolean success = adminService.register(tSlots.stream().map(portPath::child).collect(Collectors.toList()));
        if (!success) {
            log.error("Failed to register tributary slots for {}", portPath.id());
        }
    }
}
Also used : Bandwidth(org.onlab.util.Bandwidth) Resource(org.onosproject.net.resource.Resource) DiscreteResource(org.onosproject.net.resource.DiscreteResource) TributarySlot(org.onosproject.net.TributarySlot) MplsLabel(org.onlab.packet.MplsLabel) OchSignal(org.onosproject.net.OchSignal) VlanId(org.onlab.packet.VlanId)

Example 78 with VlanId

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

the class XmlParserCiscoTest method getExpectedIntfs.

private List<DeviceInterfaceDescription> getExpectedIntfs() {
    List<DeviceInterfaceDescription> intfs = new ArrayList<>();
    intfs.add(new DefaultDeviceInterfaceDescription(INTF_NAME_1, DeviceInterfaceDescription.Mode.NORMAL, Lists.newArrayList(), NO_LIMIT, NO_RATE_LIMIT));
    List<VlanId> accessList = new ArrayList<>();
    accessList.add(ACCESS_VLAN);
    intfs.add(new DefaultDeviceInterfaceDescription(INTF_NAME_2, DeviceInterfaceDescription.Mode.ACCESS, accessList, NO_LIMIT, NO_RATE_LIMIT));
    List<VlanId> trunkList1 = new ArrayList<>();
    trunkList1.add(TRUNK_VLAN_1);
    trunkList1.add(TRUNK_VLAN_2);
    intfs.add(new DefaultDeviceInterfaceDescription(INTF_NAME_3, DeviceInterfaceDescription.Mode.TRUNK, trunkList1, NO_LIMIT, NO_RATE_LIMIT));
    intfs.add(new DefaultDeviceInterfaceDescription(INTF_NAME_4, DeviceInterfaceDescription.Mode.NORMAL, Lists.newArrayList(), WITH_LIMIT, RATE_LIMIT_1));
    List<VlanId> trunkList2 = new ArrayList<>();
    trunkList2.add(TRUNK_VLAN_3);
    trunkList2.add(TRUNK_VLAN_4);
    trunkList2.add(TRUNK_VLAN_5);
    intfs.add(new DefaultDeviceInterfaceDescription(INTF_NAME_5, DeviceInterfaceDescription.Mode.TRUNK, trunkList2, WITH_LIMIT, RATE_LIMIT_2));
    return intfs;
}
Also used : DeviceInterfaceDescription(org.onosproject.net.device.DeviceInterfaceDescription) DefaultDeviceInterfaceDescription(org.onosproject.net.device.DefaultDeviceInterfaceDescription) ArrayList(java.util.ArrayList) DefaultDeviceInterfaceDescription(org.onosproject.net.device.DefaultDeviceInterfaceDescription) VlanId(org.onlab.packet.VlanId)

Example 79 with VlanId

use of org.onlab.packet.VlanId 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)

Example 80 with VlanId

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

the class InterfaceCodec method decode.

@Override
public Interface decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    String name = nullIsIllegal(json.findValue(NAME), NAME + MISSING_NAME_MESSAGE).asText();
    ConnectPoint connectPoint = ConnectPoint.deviceConnectPoint(nullIsIllegal(json.findValue(CONNECT_POINT), CONNECT_POINT + MISSING_CONNECT_POINT_MESSAGE).asText());
    List<InterfaceIpAddress> ipAddresses = Lists.newArrayList();
    if (json.findValue(IPS) != null) {
        json.findValue(IPS).forEach(ip -> {
            ipAddresses.add(InterfaceIpAddress.valueOf(ip.asText()));
        });
    }
    MacAddress macAddr = json.findValue(MAC) == null ? null : MacAddress.valueOf(json.findValue(MAC).asText());
    VlanId vlanId = json.findValue(VLAN) == null ? VlanId.NONE : VlanId.vlanId(Short.parseShort(json.findValue(VLAN).asText()));
    Interface inter = new Interface(name, connectPoint, ipAddresses, macAddr, vlanId);
    return inter;
}
Also used : MacAddress(org.onlab.packet.MacAddress) ConnectPoint(org.onosproject.net.ConnectPoint) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) VlanId(org.onlab.packet.VlanId) Interface(org.onosproject.net.intf.Interface)

Aggregations

VlanId (org.onlab.packet.VlanId)153 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)61 Test (org.junit.Test)58 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)57 DeviceId (org.onosproject.net.DeviceId)56 List (java.util.List)55 MacAddress (org.onlab.packet.MacAddress)53 Ethernet (org.onlab.packet.Ethernet)49 Collection (java.util.Collection)46 Collectors (java.util.stream.Collectors)43 CoreService (org.onosproject.core.CoreService)43 FlowRule (org.onosproject.net.flow.FlowRule)43 Collections (java.util.Collections)42 ConnectPoint (org.onosproject.net.ConnectPoint)42 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)42 TrafficSelector (org.onosproject.net.flow.TrafficSelector)39 VlanIdCriterion (org.onosproject.net.flow.criteria.VlanIdCriterion)38 ImmutableSet (com.google.common.collect.ImmutableSet)37 MplsLabel (org.onlab.packet.MplsLabel)36 Intent (org.onosproject.net.intent.Intent)34