Java Code Examples for org.onosproject.net.intf.Interface#vlan()

The following examples show how to use org.onosproject.net.intf.Interface#vlan() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FibInstaller.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Installs or removes unicast filtering objectives relating to an interface.
 *
 * @param routerIntf interface to update objectives for
 * @param install true to install the objectives, false to remove them
 */
private void updateFilteringObjective(InterfaceProvisionRequest routerIntf, boolean install) {
    Interface intf = routerIntf.intf();
    VlanId assignedVlan = (egressVlan().equals(VlanId.NONE)) ?
            VlanId.vlanId(ASSIGNED_VLAN) :
            egressVlan();

    FilteringObjective.Builder fob = DefaultFilteringObjective.builder();
    // first add filter for the interface
    fob.withKey(Criteria.matchInPort(intf.connectPoint().port()))
        .addCondition(Criteria.matchEthDst(intf.mac()))
        .addCondition(Criteria.matchVlanId(intf.vlan()));
    fob.withPriority(PRIORITY_OFFSET);
    if (intf.vlan() == VlanId.NONE) {
        TrafficTreatment tt = DefaultTrafficTreatment.builder()
                .pushVlan().setVlanId(assignedVlan).build();
        fob.withMeta(tt);
    }
    fob.permit().fromApp(fibAppId);
    sendFilteringObjective(install, fob, intf);

    // then add the same mac/vlan filters for control-plane connect point
    fob.withKey(Criteria.matchInPort(routerIntf.controlPlaneConnectPoint().port()));
    sendFilteringObjective(install, fob, intf);
}
 
Example 2
Source File: VplsTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isConfigured(ConnectPoint connectPoint) {
    for (Interface intf : AVAILABLE_INTERFACES) {
        if (!intf.connectPoint().equals(connectPoint)) {
            continue;
        }
        if (!intf.ipAddressesList().isEmpty()
                || intf.vlan() != VlanId.NONE
                || intf.vlanNative() != VlanId.NONE
                || intf.vlanUntagged() != VlanId.NONE
                || !intf.vlanTagged().isEmpty()) {
            return true;
        }
    }
    return false;
}
 
Example 3
Source File: MockInterfaceService.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isConfigured(ConnectPoint connectPoint) {
    Set<Interface> intfs = getInterfacesByPort(connectPoint);
    if (intfs == null) {
        return false;
    }
    for (Interface intf : intfs) {
        if (!intf.ipAddressesList().isEmpty() || intf.vlan() != VlanId.NONE
                || intf.vlanNative() != VlanId.NONE
                || intf.vlanUntagged() != VlanId.NONE
                || !intf.vlanTagged().isEmpty()) {
            return true;
        }
    }
    return false;
}
 
Example 4
Source File: InterfaceManager.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isConfigured(ConnectPoint connectPoint) {
    Set<Interface> intfs = interfaces.get(connectPoint);
    if (intfs == null) {
        return false;
    }
    for (Interface intf : intfs) {
        if (!intf.ipAddressesList().isEmpty() || intf.vlan() != VlanId.NONE
                || intf.vlanNative() != VlanId.NONE
                || intf.vlanUntagged() != VlanId.NONE
                || !intf.vlanTagged().isEmpty()) {
            return true;
        }
    }
    return false;
}
 
Example 5
Source File: ControlPlaneRedirectManager.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Installs or removes OSPF forwarding rules.
 *
 * @param request provisioning request containing router and interface
 * @param install true to create an add objective, false to create a remove
 *            objective
 */
private void updateOspfForwarding(InterfaceProvisionRequest request, boolean install) {
    // TODO IPv6 support has not been implemented yet
    Interface intf = request.intf();
    log.debug("{} OSPF flows for {}", operation(install), intf);

    // OSPF to router
    TrafficSelector toSelector = DefaultTrafficSelector.builder()
            .matchInPort(intf.connectPoint().port())
            .matchEthType(EthType.EtherType.IPV4.ethType().toShort())
            .matchVlanId(intf.vlan())
            .matchIPProtocol((byte) OSPF_IP_PROTO)
            .build();

    // create nextObjectives for forwarding to the controlPlaneConnectPoint
    DeviceId deviceId = intf.connectPoint().deviceId();
    PortNumber controlPlanePort = request.controlPlaneConnectPoint().port();
    int cpNextId;
    if (intf.vlan() == VlanId.NONE) {
        cpNextId = modifyNextObjective(deviceId, controlPlanePort,
                       VlanId.vlanId(ASSIGNED_VLAN),
                       true, install);
    } else {
        cpNextId = modifyNextObjective(deviceId, controlPlanePort,
                                       intf.vlan(), false, install);
    }
    flowObjectiveService.forward(intf.connectPoint().deviceId(),
            buildForwardingObjective(toSelector, null, cpNextId,
                    install ? request.info().ospfEnabled() : install, ACL_PRIORITY));
}
 
Example 6
Source File: Dhcp4HandlerImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Writes DHCP record to the store according to the response DHCP packet (Offer, Ack).
 *
 * @param ethernet the DHCP packet
 * @param dhcpPayload the DHCP payload
 */
private void writeResponseDhcpRecord(Ethernet ethernet,
                                     DHCP dhcpPayload) {
    Optional<Interface> outInterface = getClientInterface(ethernet, dhcpPayload);
    if (!outInterface.isPresent()) {
        log.warn("Failed to determine where to send {}", dhcpPayload.getPacketType());
        return;
    }

    Interface outIface = outInterface.get();
    ConnectPoint location = outIface.connectPoint();
    VlanId vlanId = getVlanIdFromRelayAgentOption(dhcpPayload);
    if (vlanId == null) {
        vlanId = outIface.vlan();
    }
    MacAddress macAddress = MacAddress.valueOf(dhcpPayload.getClientHardwareAddress());
    HostId hostId = HostId.hostId(macAddress, vlanId);
    DhcpRecord record = dhcpRelayStore.getDhcpRecord(hostId).orElse(null);
    if (record == null) {
        record = new DhcpRecord(HostId.hostId(macAddress, vlanId));
    } else {
        record = record.clone();
    }
    record.addLocation(new HostLocation(location, System.currentTimeMillis()));
    if (dhcpPayload.getPacketType() == DHCP.MsgType.DHCPACK) {
        record.ip4Address(Ip4Address.valueOf(dhcpPayload.getYourIPAddress()));
    }
    record.ip4Status(dhcpPayload.getPacketType());
    record.setDirectlyConnected(directlyConnected(dhcpPayload));
    record.updateLastSeen();
    dhcpRelayStore.updateDhcpRecord(HostId.hostId(macAddress, vlanId), record);
}
 
Example 7
Source File: SimpleFabricForwarding.java    From onos with Apache License 2.0 5 votes vote down vote up
private FilteredConnectPoint buildFilteredConnectedPoint(Interface iface) {
    Objects.requireNonNull(iface);
    TrafficSelector.Builder trafficSelector = DefaultTrafficSelector.builder();

    if (iface.vlan() != null && !iface.vlan().equals(VlanId.NONE)) {
        trafficSelector.matchVlanId(iface.vlan());
    }
    return new FilteredConnectPoint(iface.connectPoint(), trafficSelector.build());
}
 
Example 8
Source File: VplsIntentUtility.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Builds filtered connected point by a given network interface.
 *
 * @param iface the network interface
 * @return the filtered connected point of a given network interface
 */
static FilteredConnectPoint buildFilteredConnectedPoint(Interface iface) {
    Objects.requireNonNull(iface);
    TrafficSelector.Builder trafficSelector = DefaultTrafficSelector.builder();

    if (iface.vlan() != null && !iface.vlan().equals(VlanId.NONE)) {
        trafficSelector.matchVlanId(iface.vlan());
    }

    return new FilteredConnectPoint(iface.connectPoint(), trafficSelector.build());
}
 
Example 9
Source File: SdnIpFib.java    From onos with Apache License 2.0 5 votes vote down vote up
private TrafficSelector.Builder buildTrafficSelector(Interface intf) {
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();

    // TODO: Consider other tag types
    // Match the VlanId if specified in the network interface configuration
    VlanId vlanId = intf.vlan();
    if (!vlanId.equals(VlanId.NONE)) {
        selector.matchVlanId(vlanId);
    }
    return selector;
}
 
Example 10
Source File: PeerConnectivityManager.java    From onos with Apache License 2.0 5 votes vote down vote up
private Collection<PointToPointIntent> buildSpeakerIntents(BgpConfig.BgpSpeakerConfig speaker,
                                                           EncapsulationType encap) {
    List<PointToPointIntent> intents = new ArrayList<>();

    // Get the BGP Speaker VLAN Id
    VlanId bgpSpeakerVlanId = speaker.vlan();

    for (IpAddress peerAddress : speaker.peers()) {
        Interface peeringInterface = interfaceService.getMatchingInterface(peerAddress);

        if (peeringInterface == null) {
            log.debug("No peering interface found for peer {} on speaker {}",
                    peerAddress, speaker);
            continue;
        }

        IpAddress bgpSpeakerAddress = null;
        for (InterfaceIpAddress address : peeringInterface.ipAddressesList()) {
            if (address.subnetAddress().contains(peerAddress)) {
                bgpSpeakerAddress = address.ipAddress();
                break;
            }
        }

        checkNotNull(bgpSpeakerAddress);

        VlanId peerVlanId = peeringInterface.vlan();

        intents.addAll(buildIntents(speaker.connectPoint(), bgpSpeakerVlanId,
                                    bgpSpeakerAddress,
                                    peeringInterface.connectPoint(),
                                    peerVlanId,
                                    peerAddress,
                                    encap));
    }

    return intents;
}
 
Example 11
Source File: Dhcp4HandlerImpl.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Send the DHCP ack to the requester host.
 * Modify Host or Route store according to the type of DHCP.
 *
 * @param ethernetPacketAck the packet
 * @param dhcpPayload the DHCP data
 */
private void handleDhcpAck(Ethernet ethernetPacketAck, DHCP dhcpPayload) {
    Optional<Interface> outInterface = getClientInterface(ethernetPacketAck, dhcpPayload);
    if (!outInterface.isPresent()) {
        log.warn("Can't find output interface for dhcp: {}", dhcpPayload);
        return;
    }

    Interface outIface = outInterface.get();
    HostLocation hostLocation = new HostLocation(outIface.connectPoint(), System.currentTimeMillis());
    MacAddress macAddress = MacAddress.valueOf(dhcpPayload.getClientHardwareAddress());
    VlanId vlanId = getVlanIdFromRelayAgentOption(dhcpPayload);
    if (vlanId == null) {
        vlanId = outIface.vlan();
    }
    HostId hostId = HostId.hostId(macAddress, vlanId);
    Ip4Address ip = Ip4Address.valueOf(dhcpPayload.getYourIPAddress());

    if (directlyConnected(dhcpPayload)) {
        // Add to host store if it connect to network directly
        Set<IpAddress> ips = Sets.newHashSet(ip);
        Host host = hostService.getHost(hostId);

        Set<HostLocation> hostLocations = Sets.newHashSet(hostLocation);
        if (host != null) {
            // Dual homing support:
            // if host exists, use old locations and new location
            hostLocations.addAll(host.locations());
        }
        HostDescription desc = new DefaultHostDescription(macAddress, vlanId,
                                                          hostLocations, ips, false);
        // Add IP address when dhcp server give the host new ip address
        providerService.hostDetected(hostId, desc, false);
    } else {
        // Add to route store if it does not connect to network directly
        // Get gateway host IP according to host mac address
        // TODO: remove relay store here
        DhcpRecord record = dhcpRelayStore.getDhcpRecord(hostId).orElse(null);

        if (record == null) {
            log.warn("Can't find DHCP record of host {}", hostId);
            return;
        }

        MacAddress gwMac = record.nextHop().orElse(null);
        if (gwMac == null) {
            log.warn("Can't find gateway mac address from record {}", record);
            return;
        }

        HostId gwHostId = HostId.hostId(gwMac, record.vlanId());
        Host gwHost = hostService.getHost(gwHostId);

        if (gwHost == null) {
            log.warn("Can't find gateway host {}", gwHostId);
            return;
        }

        Ip4Address nextHopIp = gwHost.ipAddresses()
                .stream()
                .filter(IpAddress::isIp4)
                .map(IpAddress::getIp4Address)
                .findFirst()
                .orElse(null);

        if (nextHopIp == null) {
            log.warn("Can't find IP address of gateway {}", gwHost);
            return;
        }

        Route route = new Route(Route.Source.DHCP, ip.toIpPrefix(), nextHopIp);
        routeStore.replaceRoute(route);
    }
}