Search in sources :

Example 71 with VlanId

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

the class ServerInterfaceConfig method getInterfaces.

@Override
public List<DeviceInterfaceDescription> getInterfaces() {
    // Retrieve the device ID
    DeviceId deviceId = getDeviceId();
    checkNotNull(deviceId, MSG_DEVICE_ID_NULL);
    // .. and the device itself
    RestServerSBDevice device = null;
    try {
        device = (RestServerSBDevice) getDevice(deviceId);
    } catch (ClassCastException ccEx) {
        log.error("Failed to get interfaces for device {}", deviceId);
        return Collections.EMPTY_LIST;
    }
    if (device == null) {
        log.error("No device with ID {} is available for interface discovery", deviceId);
        return Collections.EMPTY_LIST;
    }
    if ((device.nics() == null) || (device.nics().size() == 0)) {
        log.error("No interfaces available on {}", deviceId);
        return Collections.EMPTY_LIST;
    }
    // List of port descriptions to return
    List<DeviceInterfaceDescription> intfDescriptions = Lists.newArrayList();
    // Sorted list of NIC ports
    Set<NicDevice> nics = new TreeSet(device.nics());
    // Iterate through the NICs of this device to populate the list
    for (NicDevice nic : nics) {
        List<VlanId> devVlanIds = getVlanIdListForDevice(nic);
        Mode devMode = getDeviceMode(devVlanIds);
        // Create an interface description and add it to the list
        intfDescriptions.add(new DefaultDeviceInterfaceDescription(nic.name(), devMode, devVlanIds, RATE_LIMIT_STATUS, NO_LIMIT));
    }
    return ImmutableList.copyOf(intfDescriptions);
}
Also used : NicDevice(org.onosproject.drivers.server.devices.nic.NicDevice) DeviceId(org.onosproject.net.DeviceId) TreeSet(java.util.TreeSet) DeviceInterfaceDescription(org.onosproject.net.device.DeviceInterfaceDescription) DefaultDeviceInterfaceDescription(org.onosproject.net.device.DefaultDeviceInterfaceDescription) Mode(org.onosproject.net.device.DeviceInterfaceDescription.Mode) DefaultDeviceInterfaceDescription(org.onosproject.net.device.DefaultDeviceInterfaceDescription) RestServerSBDevice(org.onosproject.drivers.server.devices.RestServerSBDevice) VlanId(org.onlab.packet.VlanId)

Example 72 with VlanId

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

the class ServerInterfaceConfig method getVlanIdListForDevice.

/**
 * Returns a list of VLAN IDs associated with a NIC device.
 *
 * @param nic the NIC device to be queried
 * @return a list of VLAN IDs (if any)
 */
private List<VlanId> getVlanIdListForDevice(NicDevice nic) {
    checkNotNull(nic, MSG_DEVICE_NULL);
    List<VlanId> vlanIds = Lists.newArrayList();
    short vlanIdValue = 0;
    for (RxFilter rxFilter : nic.rxFilterMechanisms().rxFilters()) {
        if (rxFilter == RxFilter.VLAN) {
            vlanIds.add(VlanId.vlanId(vlanIdValue++));
        }
    }
    return ImmutableList.copyOf(vlanIds);
}
Also used : RxFilter(org.onosproject.drivers.server.devices.nic.NicRxFilter.RxFilter) VlanId(org.onlab.packet.VlanId)

Example 73 with VlanId

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

the class NetworkConfigHostProvider method readInitialConfig.

private void readInitialConfig() {
    networkConfigRegistry.getSubjects(HostId.class).forEach(hostId -> {
        MacAddress mac = hostId.mac();
        VlanId vlan = hostId.vlanId();
        BasicHostConfig hostConfig = networkConfigRegistry.getConfig(hostId, BasicHostConfig.class);
        Set<IpAddress> ipAddresses = hostConfig.ipAddresses();
        Set<HostLocation> locs = hostConfig.locations();
        if (locs != null) {
            Set<HostLocation> locations = locs.stream().map(hostLocation -> new HostLocation(hostLocation, System.currentTimeMillis())).collect(Collectors.toSet());
            // auxLocations allows to be null
            Set<HostLocation> auxLocations = hostConfig.auxLocations();
            if (auxLocations != null) {
                auxLocations = auxLocations.stream().map(auxLocation -> new HostLocation(auxLocation, System.currentTimeMillis())).collect(Collectors.toSet());
            }
            VlanId innerVlan = hostConfig.innerVlan();
            EthType outerTpid = hostConfig.outerTpid();
            addHost(mac, vlan, locations, auxLocations, ipAddresses, innerVlan, outerTpid);
        } else {
            log.warn("Host {} configuration {} is missing locations", hostId, hostConfig);
        }
    });
}
Also used : NetworkConfigRegistry(org.onosproject.net.config.NetworkConfigRegistry) HostLocation(org.onosproject.net.HostLocation) HostProviderRegistry(org.onosproject.net.host.HostProviderRegistry) Host(org.onosproject.net.Host) CoreService(org.onosproject.core.CoreService) NetworkConfigEvent(org.onosproject.net.config.NetworkConfigEvent) LoggerFactory(org.slf4j.LoggerFactory) HostProviderService(org.onosproject.net.host.HostProviderService) Component(org.osgi.service.component.annotations.Component) DefaultHostDescription(org.onosproject.net.host.DefaultHostDescription) ApplicationId(org.onosproject.core.ApplicationId) BasicHostConfig(org.onosproject.net.config.basics.BasicHostConfig) Activate(org.osgi.service.component.annotations.Activate) HostId(org.onosproject.net.HostId) IpAddress(org.onlab.packet.IpAddress) AbstractProvider(org.onosproject.net.provider.AbstractProvider) Logger(org.slf4j.Logger) Deactivate(org.osgi.service.component.annotations.Deactivate) HostProvider(org.onosproject.net.host.HostProvider) VlanId(org.onlab.packet.VlanId) Set(java.util.Set) ProviderId(org.onosproject.net.provider.ProviderId) Collectors(java.util.stream.Collectors) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) EthType(org.onlab.packet.EthType) MacAddress(org.onlab.packet.MacAddress) Reference(org.osgi.service.component.annotations.Reference) HostDescription(org.onosproject.net.host.HostDescription) NetworkConfigListener(org.onosproject.net.config.NetworkConfigListener) Collections(java.util.Collections) EthType(org.onlab.packet.EthType) HostLocation(org.onosproject.net.HostLocation) IpAddress(org.onlab.packet.IpAddress) HostId(org.onosproject.net.HostId) MacAddress(org.onlab.packet.MacAddress) VlanId(org.onlab.packet.VlanId) BasicHostConfig(org.onosproject.net.config.basics.BasicHostConfig)

Example 74 with VlanId

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

the class FlowEntryBuilder method buildSelector.

// CHECKSTYLE IGNORE MethodLength FOR NEXT 1 LINES
private TrafficSelector buildSelector() {
    MacAddress mac;
    Ip4Prefix ip4Prefix;
    Ip6Address ip6Address;
    Ip6Prefix ip6Prefix;
    Ip4Address ip;
    ExtensionSelectorInterpreter selectorInterpreter;
    if (driverHandler.hasBehaviour(ExtensionSelectorInterpreter.class)) {
        selectorInterpreter = driverHandler.behaviour(ExtensionSelectorInterpreter.class);
    } else {
        selectorInterpreter = null;
    }
    TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
    for (MatchField<?> field : match.getMatchFields()) {
        switch(field.id) {
            case IN_PORT:
                builder.matchInPort(PortNumber.portNumber(match.get(MatchField.IN_PORT).getPortNumber()));
                break;
            case IN_PHY_PORT:
                builder.matchInPhyPort(PortNumber.portNumber(match.get(MatchField.IN_PHY_PORT).getPortNumber()));
                break;
            case METADATA:
                long metadata = match.get(MatchField.METADATA).getValue().getValue();
                builder.matchMetadata(metadata);
                break;
            case ETH_DST:
                if (match.isPartiallyMasked(MatchField.ETH_DST)) {
                    Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac = match.getMasked(MatchField.ETH_DST);
                    builder.matchEthDstMasked(MacAddress.valueOf(maskedMac.getValue().getLong()), MacAddress.valueOf(maskedMac.getMask().getLong()));
                } else {
                    mac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong());
                    builder.matchEthDst(mac);
                }
                break;
            case ETH_SRC:
                if (match.isPartiallyMasked(MatchField.ETH_SRC)) {
                    Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac = match.getMasked(MatchField.ETH_SRC);
                    builder.matchEthSrcMasked(MacAddress.valueOf(maskedMac.getValue().getLong()), MacAddress.valueOf(maskedMac.getMask().getLong()));
                } else {
                    mac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong());
                    builder.matchEthSrc(mac);
                }
                break;
            case ETH_TYPE:
                int ethType = match.get(MatchField.ETH_TYPE).getValue();
                builder.matchEthType((short) ethType);
                break;
            case VLAN_VID:
                if (selectorInterpreter != null && selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type())) {
                    if (isOF13OrLater(match)) {
                        OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.VLAN_VID);
                        builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
                    } else {
                        break;
                    }
                } else {
                    VlanId vlanId = null;
                    if (match.isPartiallyMasked(MatchField.VLAN_VID)) {
                        Masked<OFVlanVidMatch> masked = match.getMasked(MatchField.VLAN_VID);
                        if (masked.getValue().equals(OFVlanVidMatch.PRESENT) && masked.getMask().equals(OFVlanVidMatch.PRESENT)) {
                            vlanId = VlanId.ANY;
                        }
                    } else {
                        if (!match.get(MatchField.VLAN_VID).isPresentBitSet()) {
                            vlanId = VlanId.NONE;
                        } else {
                            vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan());
                        }
                    }
                    if (vlanId != null) {
                        builder.matchVlanId(vlanId);
                    }
                }
                break;
            case VLAN_PCP:
                byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue();
                builder.matchVlanPcp(vlanPcp);
                break;
            case IP_DSCP:
                byte ipDscp = match.get(MatchField.IP_DSCP).getDscpValue();
                builder.matchIPDscp(ipDscp);
                break;
            case IP_ECN:
                byte ipEcn = match.get(MatchField.IP_ECN).getEcnValue();
                builder.matchIPEcn(ipEcn);
                break;
            case IP_PROTO:
                short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber();
                builder.matchIPProtocol((byte) proto);
                break;
            case IPV4_SRC:
                if (match.isPartiallyMasked(MatchField.IPV4_SRC)) {
                    Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC);
                    ip4Prefix = Ip4Prefix.valueOf(maskedIp.getValue().getInt(), maskedIp.getMask().asCidrMaskLength());
                } else {
                    ip4Prefix = Ip4Prefix.valueOf(match.get(MatchField.IPV4_SRC).getInt(), Ip4Prefix.MAX_MASK_LENGTH);
                }
                builder.matchIPSrc(ip4Prefix);
                break;
            case IPV4_DST:
                if (match.isPartiallyMasked(MatchField.IPV4_DST)) {
                    Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST);
                    ip4Prefix = Ip4Prefix.valueOf(maskedIp.getValue().getInt(), maskedIp.getMask().asCidrMaskLength());
                } else {
                    ip4Prefix = Ip4Prefix.valueOf(match.get(MatchField.IPV4_DST).getInt(), Ip4Prefix.MAX_MASK_LENGTH);
                }
                builder.matchIPDst(ip4Prefix);
                break;
            case TCP_SRC:
                if (match.isPartiallyMasked(MatchField.TCP_SRC)) {
                    Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort = match.getMasked(MatchField.TCP_SRC);
                    builder.matchTcpSrcMasked(TpPort.tpPort(maskedPort.getValue().getPort()), TpPort.tpPort(maskedPort.getMask().getPort()));
                } else {
                    builder.matchTcpSrc(TpPort.tpPort(match.get(MatchField.TCP_SRC).getPort()));
                }
                break;
            case TCP_DST:
                if (match.isPartiallyMasked(MatchField.TCP_DST)) {
                    Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort = match.getMasked(MatchField.TCP_DST);
                    builder.matchTcpDstMasked(TpPort.tpPort(maskedPort.getValue().getPort()), TpPort.tpPort(maskedPort.getMask().getPort()));
                } else {
                    builder.matchTcpDst(TpPort.tpPort(match.get(MatchField.TCP_DST).getPort()));
                }
                break;
            case UDP_SRC:
                if (match.isPartiallyMasked(MatchField.UDP_SRC)) {
                    Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort = match.getMasked(MatchField.UDP_SRC);
                    builder.matchUdpSrcMasked(TpPort.tpPort(maskedPort.getValue().getPort()), TpPort.tpPort(maskedPort.getMask().getPort()));
                } else {
                    builder.matchUdpSrc(TpPort.tpPort(match.get(MatchField.UDP_SRC).getPort()));
                }
                break;
            case UDP_DST:
                if (match.isPartiallyMasked(MatchField.UDP_DST)) {
                    Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort = match.getMasked(MatchField.UDP_DST);
                    builder.matchUdpDstMasked(TpPort.tpPort(maskedPort.getValue().getPort()), TpPort.tpPort(maskedPort.getMask().getPort()));
                } else {
                    builder.matchUdpDst(TpPort.tpPort(match.get(MatchField.UDP_DST).getPort()));
                }
                break;
            case MPLS_LABEL:
                builder.matchMplsLabel(MplsLabel.mplsLabel((int) match.get(MatchField.MPLS_LABEL).getValue()));
                break;
            case MPLS_BOS:
                builder.matchMplsBos(match.get(MatchField.MPLS_BOS).getValue());
                break;
            case SCTP_SRC:
                if (match.isPartiallyMasked(MatchField.SCTP_SRC)) {
                    Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort = match.getMasked(MatchField.SCTP_SRC);
                    builder.matchSctpSrcMasked(TpPort.tpPort(maskedPort.getValue().getPort()), TpPort.tpPort(maskedPort.getMask().getPort()));
                } else {
                    builder.matchSctpSrc(TpPort.tpPort(match.get(MatchField.SCTP_SRC).getPort()));
                }
                break;
            case SCTP_DST:
                if (match.isPartiallyMasked(MatchField.SCTP_DST)) {
                    Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort = match.getMasked(MatchField.SCTP_DST);
                    builder.matchSctpDstMasked(TpPort.tpPort(maskedPort.getValue().getPort()), TpPort.tpPort(maskedPort.getMask().getPort()));
                } else {
                    builder.matchSctpDst(TpPort.tpPort(match.get(MatchField.SCTP_DST).getPort()));
                }
                break;
            case ICMPV4_TYPE:
                byte icmpType = (byte) match.get(MatchField.ICMPV4_TYPE).getType();
                builder.matchIcmpType(icmpType);
                break;
            case ICMPV4_CODE:
                byte icmpCode = (byte) match.get(MatchField.ICMPV4_CODE).getCode();
                builder.matchIcmpCode(icmpCode);
                break;
            case IPV6_SRC:
                if (match.isPartiallyMasked(MatchField.IPV6_SRC)) {
                    Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC);
                    ip6Prefix = Ip6Prefix.valueOf(maskedIp.getValue().getBytes(), maskedIp.getMask().asCidrMaskLength());
                } else {
                    ip6Prefix = Ip6Prefix.valueOf(match.get(MatchField.IPV6_SRC).getBytes(), Ip6Prefix.MAX_MASK_LENGTH);
                }
                builder.matchIPv6Src(ip6Prefix);
                break;
            case IPV6_DST:
                if (match.isPartiallyMasked(MatchField.IPV6_DST)) {
                    Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST);
                    ip6Prefix = Ip6Prefix.valueOf(maskedIp.getValue().getBytes(), maskedIp.getMask().asCidrMaskLength());
                } else {
                    ip6Prefix = Ip6Prefix.valueOf(match.get(MatchField.IPV6_DST).getBytes(), Ip6Prefix.MAX_MASK_LENGTH);
                }
                builder.matchIPv6Dst(ip6Prefix);
                break;
            case IPV6_FLABEL:
                int flowLabel = match.get(MatchField.IPV6_FLABEL).getIPv6FlowLabelValue();
                builder.matchIPv6FlowLabel(flowLabel);
                break;
            case ICMPV6_TYPE:
                byte icmpv6type = (byte) match.get(MatchField.ICMPV6_TYPE).getValue();
                builder.matchIcmpv6Type(icmpv6type);
                break;
            case ICMPV6_CODE:
                byte icmpv6code = (byte) match.get(MatchField.ICMPV6_CODE).getValue();
                builder.matchIcmpv6Code(icmpv6code);
                break;
            case IPV6_ND_TARGET:
                ip6Address = Ip6Address.valueOf(match.get(MatchField.IPV6_ND_TARGET).getBytes());
                builder.matchIPv6NDTargetAddress(ip6Address);
                break;
            case IPV6_ND_SLL:
                mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_SLL).getLong());
                builder.matchIPv6NDSourceLinkLayerAddress(mac);
                break;
            case IPV6_ND_TLL:
                mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_TLL).getLong());
                builder.matchIPv6NDTargetLinkLayerAddress(mac);
                break;
            case IPV6_EXTHDR:
                builder.matchIPv6ExthdrFlags((short) match.get(MatchField.IPV6_EXTHDR).getValue());
                break;
            case OCH_SIGID:
                CircuitSignalID sigId = match.get(MatchField.OCH_SIGID);
                builder.add(matchLambda(Lambda.ochSignal(lookupGridType(sigId.getGridType()), lookupChannelSpacing(sigId.getChannelSpacing()), sigId.getChannelNumber(), sigId.getSpectralWidth())));
                break;
            case OCH_SIGTYPE:
                U8 sigType = match.get(MatchField.OCH_SIGTYPE);
                builder.add(matchOchSignalType(lookupOchSignalType((byte) sigType.getValue())));
                break;
            case EXP_OCH_SIG_ID:
                try {
                    CircuitSignalID expSigId = match.get(MatchField.EXP_OCH_SIG_ID);
                    builder.add(matchLambda(Lambda.ochSignal(lookupGridType(expSigId.getGridType()), lookupChannelSpacing(expSigId.getChannelSpacing()), expSigId.getChannelNumber(), expSigId.getSpectralWidth())));
                } catch (NoMappingFoundException e) {
                    log.warn(e.getMessage());
                    break;
                }
                break;
            case EXP_OCH_SIGTYPE:
                try {
                    U8 expOchSigType = match.get(MatchField.EXP_OCH_SIGTYPE);
                    builder.add(matchOchSignalType(lookupOchSignalType((byte) expOchSigType.getValue())));
                } catch (NoMappingFoundException e) {
                    log.warn(e.getMessage());
                    break;
                }
                break;
            case EXP_ODU_SIG_ID:
                OduSignalId oduSignalId = OduSignalId.oduSignalId(match.get(MatchField.EXP_ODU_SIG_ID).getTpn(), match.get(MatchField.EXP_ODU_SIG_ID).getTslen(), match.get(MatchField.EXP_ODU_SIG_ID).getTsmap());
                builder.add(matchOduSignalId(oduSignalId));
                break;
            case EXP_ODU_SIGTYPE:
                try {
                    U8 oduSigType = match.get(MatchField.EXP_ODU_SIGTYPE);
                    builder.add(matchOduSignalType(lookupOduSignalType((byte) oduSigType.getValue())));
                } catch (NoMappingFoundException e) {
                    log.warn(e.getMessage());
                    break;
                }
                break;
            case TUNNEL_ID:
                long tunnelId = match.get(MatchField.TUNNEL_ID).getValue();
                builder.matchTunnelId(tunnelId);
                break;
            case ARP_OP:
                int arpOp = match.get(MatchField.ARP_OP).getOpcode();
                builder.matchArpOp(arpOp);
                break;
            case ARP_SHA:
                mac = MacAddress.valueOf(match.get(MatchField.ARP_SHA).getLong());
                builder.matchArpSha(mac);
                break;
            case ARP_SPA:
                ip = Ip4Address.valueOf(match.get(MatchField.ARP_SPA).getInt());
                builder.matchArpSpa(ip);
                break;
            case ARP_THA:
                mac = MacAddress.valueOf(match.get(MatchField.ARP_THA).getLong());
                builder.matchArpTha(mac);
                break;
            case ARP_TPA:
                ip = Ip4Address.valueOf(match.get(MatchField.ARP_TPA).getInt());
                builder.matchArpTpa(ip);
                break;
            case NSP:
                if (selectorInterpreter != null) {
                    try {
                        OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.NSP);
                        builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
                    } catch (UnsupportedOperationException e) {
                        log.debug(e.getMessage());
                    }
                }
                break;
            case NSI:
                if (selectorInterpreter != null) {
                    try {
                        OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.NSI);
                        builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
                    } catch (UnsupportedOperationException e) {
                        log.debug(e.getMessage());
                    }
                }
                break;
            case ENCAP_ETH_TYPE:
                if (selectorInterpreter != null) {
                    try {
                        OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.ENCAP_ETH_TYPE);
                        builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
                    } catch (UnsupportedOperationException e) {
                        log.debug(e.getMessage());
                    }
                }
                break;
            case CONNTRACK_STATE:
                if (selectorInterpreter != null && selectorInterpreter.supported(ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_STATE.type())) {
                    try {
                        OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.CONNTRACK_STATE);
                        builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
                    } catch (UnsupportedOperationException e) {
                        log.debug(e.getMessage());
                    }
                }
                break;
            case CONNTRACK_ZONE:
                if (selectorInterpreter != null && selectorInterpreter.supported(ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_ZONE.type())) {
                    try {
                        OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.CONNTRACK_ZONE);
                        builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
                    } catch (UnsupportedOperationException e) {
                        log.debug(e.getMessage());
                    }
                }
                break;
            case CONNTRACK_MARK:
                if (selectorInterpreter != null && selectorInterpreter.supported(ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_MARK.type())) {
                    try {
                        OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.CONNTRACK_MARK);
                        builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
                    } catch (UnsupportedOperationException e) {
                        log.debug(e.getMessage());
                    }
                }
                break;
            case OFDPA_OVID:
                if (selectorInterpreter != null && selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_OVID.type())) {
                    if (isOF13OrLater(match)) {
                        OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.OFDPA_OVID);
                        builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
                    } else {
                        break;
                    }
                }
                break;
            case OFDPA_MPLS_L2_PORT:
                if (selectorInterpreter != null && selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_MPLS_L2_PORT.type())) {
                    if (isOF13OrLater(match)) {
                        OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.OFDPA_MPLS_L2_PORT);
                        builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
                    } else {
                        break;
                    }
                }
                break;
            case OFDPA_ALLOW_VLAN_TRANSLATION:
                if (selectorInterpreter != null && selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_ALLOW_VLAN_TRANSLATION.type())) {
                    if (isOF13OrLater(match)) {
                        OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.OFDPA_ALLOW_VLAN_TRANSLATION);
                        builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
                    } else {
                        break;
                    }
                }
                break;
            case OFDPA_ACTSET_OUTPUT:
                if (selectorInterpreter != null && selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_ACTSET_OUTPUT.type())) {
                    if (isOF13OrLater(match)) {
                        OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.OFDPA_ACTSET_OUTPUT);
                        builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
                    } else {
                        break;
                    }
                }
                break;
            case MPLS_TC:
            default:
                log.warn("Match type {} not yet implemented.", field.id);
        }
    }
    return builder.build();
}
Also used : U8(org.projectfloodlight.openflow.types.U8) Ip4Address(org.onlab.packet.Ip4Address) IPv6Address(org.projectfloodlight.openflow.types.IPv6Address) IPv4Address(org.projectfloodlight.openflow.types.IPv4Address) Ip6Prefix(org.onlab.packet.Ip6Prefix) Ip6Address(org.onlab.packet.Ip6Address) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) OduSignalId(org.onosproject.net.OduSignalId) Instructions.modL1OduSignalId(org.onosproject.net.flow.instructions.Instructions.modL1OduSignalId) TransportPort(org.projectfloodlight.openflow.types.TransportPort) VlanId(org.onlab.packet.VlanId) OFVlanVidMatch(org.projectfloodlight.openflow.types.OFVlanVidMatch) CircuitSignalID(org.projectfloodlight.openflow.types.CircuitSignalID) MacAddress(org.onlab.packet.MacAddress) ExtensionSelectorInterpreter(org.onosproject.openflow.controller.ExtensionSelectorInterpreter) OFOxm(org.projectfloodlight.openflow.protocol.oxm.OFOxm) Ip4Prefix(org.onlab.packet.Ip4Prefix)

Example 75 with VlanId

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

the class Dhcp4HandlerImpl method getClientInterface.

/**
 * Gets output interface of a dhcp packet.
 * If option 82 exists in the dhcp packet and the option was sent by
 * ONOS (circuit format is correct), use the connect
 * point and vlan id from circuit id; otherwise, find host by destination
 * address and use vlan id from sender (dhcp server).
 *
 * @param ethPacket the ethernet packet
 * @param dhcpPayload the dhcp packet
 * @return an interface represent the output port and vlan; empty value
 *         if the host or circuit id not found
 */
private Optional<Interface> getClientInterface(Ethernet ethPacket, DHCP dhcpPayload) {
    VlanId originalPacketVlanId = VlanId.vlanId(ethPacket.getVlanID());
    DhcpRelayAgentOption option = (DhcpRelayAgentOption) dhcpPayload.getOption(OptionCode_CircuitID);
    DhcpOption circuitIdSubOption = option.getSubOption(CIRCUIT_ID.getValue());
    try {
        CircuitId circuitId = CircuitId.deserialize(circuitIdSubOption.getData());
        ConnectPoint connectPoint = ConnectPoint.deviceConnectPoint(circuitId.connectPoint());
        VlanId vlanId = circuitId.vlanId();
        return interfaceService.getInterfacesByPort(connectPoint).stream().filter(iface -> interfaceContainsVlan(iface, vlanId)).findFirst();
    } catch (IllegalArgumentException ex) {
        // invalid circuit format, didn't sent by ONOS
        log.debug("Invalid circuit {}, use information from dhcp payload", circuitIdSubOption.getData());
    }
    // Use Vlan Id from DHCP server if DHCP relay circuit id was not
    // sent by ONOS or circuit Id can't be parsed
    // TODO: remove relay store from this method
    MacAddress dstMac = valueOf(dhcpPayload.getClientHardwareAddress());
    VlanId filteredVlanId = getVlanIdFromDhcpRecord(dstMac, originalPacketVlanId);
    // Get the vlan from the dhcp record
    if (filteredVlanId == null) {
        log.debug("not find the matching DHCP record for mac: {} and vlan: {}", dstMac, originalPacketVlanId);
        return Optional.empty();
    }
    Optional<DhcpRecord> dhcpRecord = dhcpRelayStore.getDhcpRecord(HostId.hostId(dstMac, filteredVlanId));
    ConnectPoint clientConnectPoint = dhcpRecord.map(DhcpRecord::locations).orElse(Collections.emptySet()).stream().reduce((hl1, hl2) -> {
        // find latest host connect point
        if (hl1 == null || hl2 == null) {
            return hl1 == null ? hl2 : hl1;
        }
        return hl1.time() > hl2.time() ? hl1 : hl2;
    }).orElse(null);
    if (clientConnectPoint != null) {
        return interfaceService.getInterfacesByPort(clientConnectPoint).stream().filter(iface -> interfaceContainsVlan(iface, filteredVlanId)).findFirst();
    }
    return Optional.empty();
}
Also used : DeviceService(org.onosproject.net.device.DeviceService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError) OptionCode_END(org.onlab.packet.DHCP.DHCPOptionCode.OptionCode_END) IgnoreDhcpConfig(org.onosproject.dhcprelay.config.IgnoreDhcpConfig) Port(org.onosproject.net.Port) ApplicationId(org.onosproject.core.ApplicationId) DhcpRelayStore(org.onosproject.dhcprelay.store.DhcpRelayStore) Ip4Address(org.onlab.packet.Ip4Address) Deactivate(org.osgi.service.component.annotations.Deactivate) OptionCode_MessageType(org.onlab.packet.DHCP.DHCPOptionCode.OptionCode_MessageType) Set(java.util.Set) MacAddress.valueOf(org.onlab.packet.MacAddress.valueOf) PacketService(org.onosproject.net.packet.PacketService) DhcpServerConfig(org.onosproject.dhcprelay.config.DhcpServerConfig) DeviceId(org.onosproject.net.DeviceId) LEARN_ROUTE_FROM_LEASE_QUERY_DEFAULT(org.onosproject.dhcprelay.OsgiPropertyConstants.LEARN_ROUTE_FROM_LEASE_QUERY_DEFAULT) Dictionary(java.util.Dictionary) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Pipeliner(org.onosproject.net.behaviour.Pipeliner) REMOVE(org.onosproject.net.flowobjective.Objective.Operation.REMOVE) HostProviderRegistry(org.onosproject.net.host.HostProviderRegistry) Tools(org.onlab.util.Tools) Host(org.onosproject.net.Host) RouteStore(org.onosproject.routeservice.RouteStore) ComponentContext(org.osgi.service.component.ComponentContext) LEARN_ROUTE_FROM_LEASE_QUERY(org.onosproject.dhcprelay.OsgiPropertyConstants.LEARN_ROUTE_FROM_LEASE_QUERY) HostListener(org.onosproject.net.host.HostListener) InterfaceService(org.onosproject.net.intf.InterfaceService) HostService(org.onosproject.net.host.HostService) Multimaps(com.google.common.collect.Multimaps) ArrayList(java.util.ArrayList) Component(org.osgi.service.component.annotations.Component) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) CIRCUIT_ID(org.onlab.packet.dhcp.DhcpRelayAgentOption.RelayAgentInfoOptions.CIRCUIT_ID) OptionCode_CircuitID(org.onlab.packet.DHCP.DHCPOptionCode.OptionCode_CircuitID) CircuitId(org.onlab.packet.dhcp.CircuitId) DhcpRelayAgentOption(org.onlab.packet.dhcp.DhcpRelayAgentOption) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) TpPort(org.onlab.packet.TpPort) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) BasePacket(org.onlab.packet.BasePacket) Executor(java.util.concurrent.Executor) HostProvider(org.onosproject.net.host.HostProvider) VlanId(org.onlab.packet.VlanId) ProviderId(org.onosproject.net.provider.ProviderId) IPv4(org.onlab.packet.IPv4) DhcpRecord(org.onosproject.dhcprelay.store.DhcpRecord) Objective(org.onosproject.net.flowobjective.Objective) MacAddress(org.onlab.packet.MacAddress) DHCP(org.onlab.packet.DHCP) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) Route(org.onosproject.routeservice.Route) HostLocation(org.onosproject.net.HostLocation) Interface(org.onosproject.net.intf.Interface) CoreService(org.onosproject.core.CoreService) LoggerFactory(org.slf4j.LoggerFactory) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) ByteBuffer(java.nio.ByteBuffer) Ethernet(org.onlab.packet.Ethernet) HostProviderService(org.onosproject.net.host.HostProviderService) HashMultimap(com.google.common.collect.HashMultimap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DhcpServerInfo(org.onosproject.dhcprelay.api.DhcpServerInfo) ImmutableSet(com.google.common.collect.ImmutableSet) Device(org.onosproject.net.Device) Collection(java.util.Collection) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) PacketContext(org.onosproject.net.packet.PacketContext) Optional(java.util.Optional) HostDescription(org.onosproject.net.host.HostDescription) ADD(org.onosproject.net.flowobjective.Objective.Operation.ADD) Multimap(com.google.common.collect.Multimap) FlowObjectiveService(org.onosproject.net.flowobjective.FlowObjectiveService) DefaultHostDescription(org.onosproject.net.host.DefaultHostDescription) OutboundPacket(org.onosproject.net.packet.OutboundPacket) HostEvent(org.onosproject.net.host.HostEvent) Activate(org.osgi.service.component.annotations.Activate) HostId(org.onosproject.net.HostId) IpAddress(org.onlab.packet.IpAddress) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Logger(org.slf4j.Logger) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) UDP(org.onlab.packet.UDP) DhcpHandler(org.onosproject.dhcprelay.api.DhcpHandler) DhcpOption(org.onlab.packet.dhcp.DhcpOption) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Modified(org.osgi.service.component.annotations.Modified) PacketPriority(org.onosproject.net.packet.PacketPriority) Reference(org.osgi.service.component.annotations.Reference) Collections(java.util.Collections) DhcpRelayAgentOption(org.onlab.packet.dhcp.DhcpRelayAgentOption) CircuitId(org.onlab.packet.dhcp.CircuitId) DhcpOption(org.onlab.packet.dhcp.DhcpOption) DhcpRecord(org.onosproject.dhcprelay.store.DhcpRecord) MacAddress(org.onlab.packet.MacAddress) ConnectPoint(org.onosproject.net.ConnectPoint) VlanId(org.onlab.packet.VlanId)

Aggregations

VlanId (org.onlab.packet.VlanId)147 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)60 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)56 DeviceId (org.onosproject.net.DeviceId)55 List (java.util.List)53 Test (org.junit.Test)53 MacAddress (org.onlab.packet.MacAddress)49 Collection (java.util.Collection)45 Ethernet (org.onlab.packet.Ethernet)44 CoreService (org.onosproject.core.CoreService)43 FlowRule (org.onosproject.net.flow.FlowRule)43 Collections (java.util.Collections)41 Collectors (java.util.stream.Collectors)41 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)41 TrafficSelector (org.onosproject.net.flow.TrafficSelector)38 ImmutableSet (com.google.common.collect.ImmutableSet)37 ConnectPoint (org.onosproject.net.ConnectPoint)37 VlanIdCriterion (org.onosproject.net.flow.criteria.VlanIdCriterion)37 MplsLabel (org.onlab.packet.MplsLabel)35 Intent (org.onosproject.net.intent.Intent)34