Java Code Examples for org.onosproject.net.ConnectPoint#deviceId()

The following examples show how to use org.onosproject.net.ConnectPoint#deviceId() . 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: DistributedFlowStatisticStore.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public Set<FlowEntry> getCurrentFlowStatistic(ConnectPoint connectPoint) {
    final DeviceId deviceId = connectPoint.deviceId();

    NodeId master = mastershipService.getMasterFor(deviceId);
    if (master == null) {
        log.warn("No master for {}", deviceId);
        return Collections.emptySet();
    }

    if (Objects.equal(local, master)) {
        return getCurrentStatisticInternal(connectPoint);
    } else {
        return Tools.futureGetOrElse(clusterCommunicator.sendAndReceive(
                        connectPoint,
                        GET_CURRENT,
                        SERIALIZER::encode,
                        SERIALIZER::decode,
                        master),
                STATISTIC_STORE_TIMEOUT_MILLIS,
                TimeUnit.MILLISECONDS,
                Collections.emptySet());
    }
}
 
Example 2
Source File: DistributedStatisticStore.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public Set<FlowEntry> getCurrentStatistic(ConnectPoint connectPoint) {
    final DeviceId deviceId = connectPoint.deviceId();
    NodeId master = mastershipService.getMasterFor(deviceId);
    if (master == null) {
        log.warn("No master for {}", deviceId);
        return Collections.emptySet();
    }
    if (master.equals(clusterService.getLocalNode().id())) {
        return getCurrentStatisticInternal(connectPoint);
    } else {
        return Tools.futureGetOrElse(clusterCommunicator.sendAndReceive(
                                    connectPoint,
                                    GET_CURRENT,
                                    SERIALIZER::encode,
                                    SERIALIZER::decode,
                                    master),
                               STATISTIC_STORE_TIMEOUT_MILLIS,
                               TimeUnit.MILLISECONDS,
                               Collections.emptySet());
    }

}
 
Example 3
Source File: DistributedFlowStatisticStore.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public Set<FlowEntry> getPreviousFlowStatistic(ConnectPoint connectPoint) {
    final DeviceId deviceId = connectPoint.deviceId();

    NodeId master = mastershipService.getMasterFor(deviceId);
    if (master == null) {
        log.warn("No master for {}", deviceId);
        return Collections.emptySet();
    }

    if (Objects.equal(local, master)) {
        return getPreviousStatisticInternal(connectPoint);
    } else {
        return Tools.futureGetOrElse(clusterCommunicator.sendAndReceive(
                        connectPoint,
                        GET_PREVIOUS,
                        SERIALIZER::encode,
                        SERIALIZER::decode,
                        master),
                STATISTIC_STORE_TIMEOUT_MILLIS,
                TimeUnit.MILLISECONDS,
                Collections.emptySet());
    }
}
 
Example 4
Source File: DefaultL2TunnelHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the path betwwen two connect points.
 *
 * @param srcCp source connect point
 * @param dstCp destination connect point
 * @return the path
 */
private List<Link> getPath(ConnectPoint srcCp, ConnectPoint dstCp) {

    // use SRLinkWeigher to avoid pair links, and also
    // avoid going from the spine to the leaf and to the
    // spine again, we need to have the leaf as CP1 here.
    LinkWeigher srLw = new SRLinkWeigher(srManager, srcCp.deviceId(), new HashSet<Link>());

    Set<Path> paths = srManager.topologyService.
            getPaths(srManager.topologyService.currentTopology(),
            srcCp.deviceId(), dstCp.deviceId(), srLw);

    log.debug("Paths obtained from topology service {}", paths);

    // We randomly pick a path.
    if (paths.isEmpty()) {
        return null;
    }
    int size = paths.size();
    int index = RandomUtils.nextInt(0, size);

    List<Link> result = Iterables.get(paths, index).links();
    log.debug("Randomly picked a path {}", result);

    return result;
}
 
Example 5
Source File: VplsIntentUtility.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Builds an intent key either for single-point to multi-point or
 * multi-point to single-point intents, based on a prefix that defines
 * the type of intent, the single connect point representing the single
 * source or destination for that intent, the name of the VPLS the intent
 * belongs to, and the destination host MAC address the intent reaches.
 *
 * @param prefix the key prefix
 * @param cPoint the connect point identifying the source/destination
 * @param vplsName the name of the VPLS
 * @param hostMac the source/destination MAC address
 * @param appId application ID for the key
 * @return the key to identify the intent
 */
static Key buildKey(String prefix,
                              ConnectPoint cPoint,
                              String vplsName,
                              MacAddress hostMac,
                              ApplicationId appId) {
    String keyString = vplsName +
            SEPARATOR +
            prefix +
            SEPARATOR +
            cPoint.deviceId() +
            SEPARATOR +
            cPoint.port() +
            SEPARATOR +
            hostMac;

    return Key.of(keyString, appId);
}
 
Example 6
Source File: IpHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Processes incoming IPv6 packets.
 *
 * If it is an IPv6 packet for known host, then forward it to the host.
 * If it is an IPv6 packet for unknown host in subnet, then send an NDP request
 * to the subnet.
 *
 * @param pkt incoming packet
 * @param connectPoint the target device
 */
public void processPacketIn(IPv6 pkt, ConnectPoint connectPoint) {

    DeviceId deviceId = connectPoint.deviceId();
    Ip6Address destinationAddress = Ip6Address.valueOf(pkt.getDestinationAddress());

    // IPv6 packet for know hosts
    if (!srManager.hostService.getHostsByIp(destinationAddress).isEmpty()) {
        forwardPackets(deviceId, destinationAddress);

        // IPv6 packet for unknown host in one of the configured subnets of the router
    } else if (config.inSameSubnet(deviceId, destinationAddress)) {
        srManager.icmpHandler.sendNdpRequest(deviceId, destinationAddress, connectPoint);

        // IPv6 packets for unknown host
    } else {
        log.debug("IPv6 packet for unknown host {} which is not in the subnet",
                  destinationAddress);
    }
}
 
Example 7
Source File: PointToPointIntentCompiler.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Manufactures flow rule with treatment that is defined by failover
 * group and traffic selector determined by ingress port of the intent.
 *
 * @param intent intent which is being compiled (for appId)
 * @return       a list of a singular flow rule with fast failover
 *               outport traffic treatment
 */
private List<FlowRule> createFailoverFlowRules(PointToPointIntent intent) {
    List<FlowRule> flowRules = new ArrayList<>();

    ConnectPoint ingress = intent.filteredIngressPoint().connectPoint();
    DeviceId deviceId = ingress.deviceId();

    // flow rule with failover traffic treatment
    TrafficSelector trafficSelector = DefaultTrafficSelector.builder(intent.selector())
                                                  .matchInPort(ingress.port()).build();

    FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder();
    flowRules.add(flowRuleBuilder.withSelector(trafficSelector)
                          .withTreatment(buildFailoverTreatment(deviceId, makeGroupKey(intent.id())))
                          .fromApp(intent.appId())
                          .makePermanent()
                          .forDevice(deviceId)
                          .withPriority(PRIORITY)
                          .build());

    return flowRules;
}
 
Example 8
Source File: IcmpHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
private void sendPacketOut(ConnectPoint outport, Ethernet payload) {
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().
            setOutput(outport.port()).build();
    OutboundPacket packet = new DefaultOutboundPacket(outport.deviceId(),
            treatment, ByteBuffer.wrap(payload.serialize()));
    packetService.emit(packet);
}
 
Example 9
Source File: VtnManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void process(PacketContext context) {
    InboundPacket pkt = context.inPacket();
    ConnectPoint connectPoint = pkt.receivedFrom();
    DeviceId deviceId = connectPoint.deviceId();
    Ethernet ethPkt = pkt.parsed();
    if (ethPkt == null) {
        return;
    }
    if (ethPkt.getEtherType() == Ethernet.TYPE_ARP) {
        ARP arpPacket = (ARP) ethPkt.getPayload();
        if ((arpPacket.getOpCode() == ARP.OP_REQUEST)) {
            arprequestProcess(arpPacket, deviceId);
        } else if (arpPacket.getOpCode() == ARP.OP_REPLY) {
            arpresponceProcess(arpPacket, deviceId);
        }
    } else if (ethPkt.getEtherType() == Ethernet.TYPE_IPV4) {
        if (ethPkt.getDestinationMAC().isMulticast()) {
            return;
        }
        IPv4 ip = (IPv4) ethPkt.getPayload();
        upStreamPacketProcessor(ip, deviceId);

    } else {
        return;
    }
}
 
Example 10
Source File: SfcManager.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Send packet back to classifier.
 *
 * @param context packet context
 */
private void sendPacket(PacketContext context) {

    ConnectPoint sourcePoint = context.inPacket().receivedFrom();

    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(PortNumber.TABLE).build();
    OutboundPacket packet = new DefaultOutboundPacket(sourcePoint.deviceId(), treatment, context.inPacket()
            .unparsed());
    packetService.emit(packet);
    log.trace("Sending packet: {}", packet);
}
 
Example 11
Source File: DefaultCheckLoop.java    From onos with Apache License 2.0 5 votes vote down vote up
private Set<Link> tsGetEgressLinks(ConnectPoint point) {
    Set<Link> portEgressLink = new HashSet<>();
    DeviceId deviceId = point.deviceId();

    portEgressLink.addAll(
            //all egress links
            egressLinkInfo.get(deviceId)
                    .stream()
                    .filter(l -> l.src().equals(point))
                    .collect(Collectors.toList()));

    return portEgressLink;
}
 
Example 12
Source File: TopologyViewMessageHandlerBase.java    From onos with Apache License 2.0 5 votes vote down vote up
private void addLinkCpAProps(PropertyPanel pp, ConnectPoint cp, LionBundle lion) {
    DeviceId did = cp.deviceId();

    pp.addProp(LPL_A_TYPE, lion.getSafe(LPL_A_TYPE), lion.getSafe(DEVICE))
            .addProp(LPL_A_ID, lion.getSafe(LPL_A_ID), did.toString())
            .addProp(LPL_A_FRIENDLY, lion.getSafe(LPL_A_FRIENDLY), friendlyDevice(did))
            .addProp(LPL_A_PORT, lion.getSafe(LPL_A_PORT), cp.port().toLong())
            .addSeparator();
}
 
Example 13
Source File: HostMonitor.java    From onos with Apache License 2.0 5 votes vote down vote up
public void sendProbe(ConnectPoint connectPoint, IpAddress targetIp, IpAddress sourceIp,
                      MacAddress sourceMac, VlanId vlan) {
    log.debug("Sending probe for target:{} out of intf:{} vlan:{}", targetIp, connectPoint, vlan);

    Ethernet probePacket;

    if (targetIp.isIp4()) {
        // IPv4: Use ARP
        probePacket = buildArpRequest(targetIp, sourceIp, sourceMac, vlan);
    } else {
         // IPv6: Use Neighbor Discovery. According to the NDP protocol,
         // we should use the solicitation node address as IPv6 destination
         // and the multicast mac address as Ethernet destination.
        byte[] destIp = IPv6.getSolicitNodeAddress(targetIp.toOctets());
        probePacket = NeighborSolicitation.buildNdpSolicit(
                targetIp.getIp6Address(),
                sourceIp.getIp6Address(),
                Ip6Address.valueOf(destIp),
                sourceMac,
                MacAddress.valueOf(IPv6.getMCastMacAddress(destIp)),
                vlan
        );
    }

    if (probePacket == null) {
        log.warn("Not able to build the probe packet");
        return;
    }

    TrafficTreatment treatment = DefaultTrafficTreatment.builder()
        .setOutput(connectPoint.port())
        .build();

    OutboundPacket outboundPacket =
        new DefaultOutboundPacket(connectPoint.deviceId(), treatment,
                                  ByteBuffer.wrap(probePacket.serialize()));

    packetService.emit(outboundPacket);
}
 
Example 14
Source File: TunnellingConnectivityManager.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Forwards a BGP packet to another connect point.
 *
 * @param context the packet context of the incoming packet
 */
private void forward(PacketContext context) {
    ConnectPoint outputPort = null;

    IPv4 ipv4 = (IPv4) context.inPacket().parsed().getPayload();
    IpAddress dstAddress = IpAddress.valueOf(ipv4.getDestinationAddress());

    if (context.inPacket().receivedFrom().equals(bgpSpeaker.connectPoint())) {
        if (bgpSpeaker.peers().contains(dstAddress)) {
            Interface intf = interfaceService.getMatchingInterface(dstAddress);
            if (intf != null) {
                outputPort = intf.connectPoint();
            }
        }
    } else {
        Set<Interface> interfaces =
                interfaceService.getInterfacesByPort(context.inPacket().receivedFrom());

        if (interfaces.stream()
                .flatMap(intf -> intf.ipAddressesList().stream())
                .anyMatch(ia -> ia.ipAddress().equals(dstAddress))) {
            outputPort = bgpSpeaker.connectPoint();
        }
    }

    if (outputPort != null) {
        TrafficTreatment t = DefaultTrafficTreatment.builder()
                .setOutput(outputPort.port()).build();
        OutboundPacket o = new DefaultOutboundPacket(
                outputPort.deviceId(), t, context.inPacket().unparsed());
        packetService.emit(o);
    }
}
 
Example 15
Source File: DefaultHostProbingProvider.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Send the probe packet on given port.
 *
 * @param probe the probe packet
 * @param connectPoint the port we want to probe
 */
private void sendLocationProbe(Ethernet probe, ConnectPoint connectPoint) {
    log.debug("Sending probe for host {} on location {} with probeMac {}",
            probe.getDestinationMAC(), connectPoint, probe.getSourceMAC());
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(connectPoint.port()).build();
    OutboundPacket outboundPacket = new DefaultOutboundPacket(connectPoint.deviceId(),
            treatment, ByteBuffer.wrap(probe.serialize()));
    packetService.emit(outboundPacket);
}
 
Example 16
Source File: PortAuthTracker.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Supplicant at specified connect point has logged off Radius. If
 * we are tracking this port, install a blocking flow and mark the
 * port as blocked.
 *
 * @param connectPoint supplicant connect point
 */
void radiusLogoff(ConnectPoint connectPoint) {
    DeviceId d = connectPoint.deviceId();
    PortNumber p = connectPoint.port();
    if (configured(d, p)) {
        installBlockingFlow(d, p);
        markAsBlocked(d, p);
    }
}
 
Example 17
Source File: TopologyViewMessageHandlerBase.java    From onos with Apache License 2.0 5 votes vote down vote up
private void addLinkCpBProps(PropertyPanel pp, ConnectPoint cp, LionBundle lion) {
    DeviceId did = cp.deviceId();

    pp.addProp(LPL_B_TYPE, lion.getSafe(LPL_B_TYPE), lion.getSafe(DEVICE))
            .addProp(LPL_B_ID, lion.getSafe(LPL_B_ID), did.toString())
            .addProp(LPL_B_FRIENDLY, lion.getSafe(LPL_B_FRIENDLY), friendlyDevice(did))
            .addProp(LPL_B_PORT, lion.getSafe(LPL_B_PORT), cp.port().toLong())
            .addSeparator();
}
 
Example 18
Source File: SubjectFactories.java    From onos with Apache License 2.0 4 votes vote down vote up
private static String key(ConnectPoint subject) {
    return subject.deviceId() + "/" + subject.port();
}
 
Example 19
Source File: DefaultNeighbourMessageActionsTest.java    From onos with Apache License 2.0 4 votes vote down vote up
private static OutboundPacket outbound(Ethernet packet, ConnectPoint outPort) {
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(outPort.port()).build();
    return new DefaultOutboundPacket(outPort.deviceId(),
            treatment, ByteBuffer.wrap(packet.serialize()));
}
 
Example 20
Source File: DefaultGraphDescription.java    From onos with Apache License 2.0 4 votes vote down vote up
private TopologyVertex vertexOf(ConnectPoint connectPoint) {
    DeviceId id = connectPoint.deviceId();
    TopologyVertex vertex = vertexesById.get(id);
    checkArgument(vertex != null, "Vertex missing for %s", id);
    return vertex;
}