Java Code Examples for org.onosproject.net.DeviceId#equals()

The following examples show how to use org.onosproject.net.DeviceId#equals() . 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: OpticalOduIntentCompilerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public List<Port> getPorts(DeviceId deviceId) {
    if (deviceId.equals(deviceId(DEV1))) {
        return ImmutableList.of((Port) D1P1, (Port) D1P2, (Port) D1P3);
    }

    if (deviceId.equals(deviceId(DEV2))) {
        return ImmutableList.of((Port) D2P1, (Port) D2P2);
    }

    if (deviceId.equals(deviceId(DEV3))) {
        return ImmutableList.of((Port) D3P1, (Port) D3P2, (Port) D3P3);
    }

    return Collections.emptyList();
}
 
Example 2
Source File: VtnManager.java    From onos with Apache License 2.0 6 votes vote down vote up
private void arpresponceProcess(ARP arpPacket, DeviceId deviceId) {
    MacAddress srcMac = MacAddress
            .valueOf(arpPacket.getTargetHardwareAddress());
    MacAddress dstMac = MacAddress
            .valueOf(arpPacket.getSenderHardwareAddress());
    IpAddress srcIp = IpAddress.valueOf(IPv4
            .toIPv4Address(arpPacket.getTargetProtocolAddress()));
    IpAddress dstIp = IpAddress.valueOf(IPv4
            .toIPv4Address(arpPacket.getSenderProtocolAddress()));
    FloatingIp floatingIp = floatingIpStore.get(srcIp);
    if (floatingIp == null) {
        return;
    }
    DeviceId deviceIdOfFloatingIp = getDeviceIdOfFloatingIP(floatingIp);
    if (!deviceId.equals(deviceIdOfFloatingIp)) {
        return;
    }
    if (!downloadSnatRules(deviceId, srcMac, srcIp, dstMac, dstIp,
                           floatingIp)) {
        return;
    }
}
 
Example 3
Source File: OpticalCircuitIntentCompilerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public Port getPort(DeviceId deviceId, PortNumber portNumber) {
    if (deviceId.equals(deviceId(DEV1))) {
        switch (portNumber.toString()) {
            case "1":
                return D1P1;
            case "2":
                return D1P2;
            case "3":
                return D1P3;
            default:
                return null;
        }
    }
    if (deviceId.equals(deviceId(DEV2))) {
        switch (portNumber.toString()) {
            case "1":
                return D2P1;
            case "2":
                return D2P2;
            case "3":
                return D2P3;
            default:
                return null;
        }
    }
    return null;
}
 
Example 4
Source File: OvsdbHostProviderTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void hostDetected(HostId hostId, HostDescription hostDescription, boolean replaceIps) {
    DeviceId descr = hostDescription.location().deviceId();
    if (added == null) {
        added = descr;
    } else if ((moved == null) && !descr.equals(added)) {
        moved = descr;
    } else {
        spine = descr;
    }
}
 
Example 5
Source File: OpticalCircuitIntentCompilerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public List<Port> getPorts(DeviceId deviceId) {
    if (deviceId.equals(deviceId(DEV1))) {
        return ImmutableList.of((Port) D1P1, (Port) D1P2, (Port) D1P3);
    }

    if (deviceId.equals(deviceId(DEV2))) {
        return ImmutableList.of((Port) D2P1, (Port) D2P2, (Port) D2P3);
    }
    return Collections.emptyList();
}
 
Example 6
Source File: NetworkConfigLinksProviderTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public Device getDevice(DeviceId deviceId) {
    if (deviceId.equals(dev1.id())) {
        return dev1;
    } else {
        return dev2;
    }
}
 
Example 7
Source File: BgpTopologyProviderTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void deviceConnected(DeviceId deviceId, DeviceDescription deviceDescription) {
    if (!deviceId.equals(DID2)) {
        connected.add(deviceId);
        Device device = new DefaultDevice(BgpTopologyProviderTest.providerId, deviceId, Device.Type.ROUTER,
                UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, new ChassisId(), deviceDescription.annotations());
        deviceMap.put(deviceId, device);
    }
}
 
Example 8
Source File: DestinationSet.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the label associated with given destination switch.
 *
 * @param dstSw the destination switch
 * @return integer the label associated with the destination switch
 */
public int getEdgeLabel(DeviceId dstSw) {
    if (dstSw.equals(dstSw1)) {
        return edgeLabel1;
    } else if (dstSw.equals(dstSw2)) {
        return edgeLabel2;
    }
    return NOT_ASSIGNED;
}
 
Example 9
Source File: AbstractPathService.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public Set<DisjointPath> getDisjointPaths(ElementId src, ElementId dst,
                                          LinkWeigher weigher, Map<Link, Object> riskProfile) {
    checkNotNull(src, ELEMENT_ID_NULL);
    checkNotNull(dst, ELEMENT_ID_NULL);

    LinkWeigher internalWeigher = weigher != null ? weigher : DEFAULT_WEIGHER;

    // Get the source and destination edge locations
    EdgeLink srcEdge = getEdgeLink(src, true);
    EdgeLink dstEdge = getEdgeLink(dst, false);

    // If either edge is null, bail with no paths.
    if (srcEdge == null || dstEdge == null) {
        return ImmutableSet.of();
    }

    DeviceId srcDevice = srcEdge != NOT_HOST ? srcEdge.dst().deviceId() : (DeviceId) src;
    DeviceId dstDevice = dstEdge != NOT_HOST ? dstEdge.src().deviceId() : (DeviceId) dst;

    // If the source and destination are on the same edge device, there
    // is just one path, so build it and return it.
    if (srcDevice.equals(dstDevice)) {
        return edgeToEdgePathsDisjoint(srcEdge, dstEdge, internalWeigher);
    }

    // Otherwise get all paths between the source and destination edge
    // devices.
    Topology topology = topologyService.currentTopology();
    Set<DisjointPath> paths = topologyService.getDisjointPaths(topology,
            srcDevice, dstDevice, internalWeigher, riskProfile);

    return edgeToEdgePathsDisjoint(srcEdge, dstEdge, paths, internalWeigher);
}
 
Example 10
Source File: PollingAlarmProviderTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public Device getDevice(DeviceId did) {
    if (did.equals(DEVICE_ID)) {
        return device;
    }
    return null;
}
 
Example 11
Source File: OpticalIntentsWebResource.java    From onos with Apache License 2.0 5 votes vote down vote up
private boolean isPathContiguous(List<Link> path) {
    DeviceId previousDst;
    DeviceId currentSrc;

    for (int i = 1; i < path.size(); i++) {
        previousDst = path.get(i - 1).dst().deviceId();
        currentSrc = path.get(i).src().deviceId();

        if (!previousDst.equals(currentSrc)) {
            log.debug("OpticalIntent links are not contiguous previous {} current {}", previousDst, currentSrc);
            return false;
        }
    }
    return true;
}
 
Example 12
Source File: VirtualNetworkGroupManagerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
private void testAuditWithExtraneousMissingGroups(NetworkId networkId,
                                                  DeviceId deviceId) {
    VirtualNetworkGroupManager groupManager;
    VirtualGroupProviderService providerService;
    if (networkId.id() == 1) {
        groupManager = groupManager1;
        providerService = providerService1;
    } else {
        groupManager = groupManager2;
        providerService = providerService2;
    }

    PortNumber[] ports1 = {PortNumber.portNumber(31),
            PortNumber.portNumber(32)};
    PortNumber[] ports2 = {PortNumber.portNumber(41),
            PortNumber.portNumber(42)};
    GroupId gId1 = new GroupId(1);
    Group group1 = createSouthboundGroupEntry(gId1,
                                              Arrays.asList(ports1),
                                              0, deviceId);
    GroupId gId2 = new GroupId(2);
    Group group2 = createSouthboundGroupEntry(gId2,
                                              Arrays.asList(ports2),
                                              0, deviceId);
    List<Group> groupEntries = Arrays.asList(group1, group2);
    providerService.pushGroupMetrics(deviceId, groupEntries);
    GroupKey key = new DefaultGroupKey("group1BeforeAudit".getBytes());
    Group createdGroup = groupManager.getGroup(deviceId, key);
    List<GroupOperation> expectedGroupOps = Arrays.asList(
            GroupOperation.createDeleteGroupOperation(gId1,
                                                      Group.Type.SELECT),
            GroupOperation.createDeleteGroupOperation(gId2,
                                                      Group.Type.SELECT),
            GroupOperation.createAddGroupOperation(createdGroup.id(),
                                                   Group.Type.SELECT,
                                                   createdGroup.buckets()));
    if (deviceId.equals(VDID1)) {
        provider.validate(networkId, deviceId, expectedGroupOps);
    }
}
 
Example 13
Source File: EdgeManagerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isAvailable(DeviceId deviceId) {
    for (DeviceId id : devices.keySet()) {
        if (id.equals(deviceId)) {
            return true;
        }
    }
    return false;
}
 
Example 14
Source File: GroupManagerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
private void testAuditWithExtraneousMissingGroups(DeviceId deviceId) {
    PortNumber[] ports1 = {PortNumber.portNumber(31),
            PortNumber.portNumber(32)};
    PortNumber[] ports2 = {PortNumber.portNumber(41),
            PortNumber.portNumber(42)};
    GroupId gId1 = new GroupId(1);
    Group group1 = createSouthboundGroupEntry(gId1,
                                              Arrays.asList(ports1),
                                              0, deviceId);
    GroupId gId2 = new GroupId(2);
    Group group2 = createSouthboundGroupEntry(gId2,
                                              Arrays.asList(ports2),
                                              0, deviceId);
    List<Group> groupEntries = Arrays.asList(group1, group2);
    providerService.pushGroupMetrics(deviceId, groupEntries);
    GroupKey key = new DefaultGroupKey("group1BeforeAudit".getBytes());
    Group createdGroup = groupService.getGroup(deviceId, key);
    List<GroupOperation> expectedGroupOps = Arrays.asList(
            GroupOperation.createDeleteGroupOperation(gId1,
                                                      Group.Type.SELECT),
            GroupOperation.createDeleteGroupOperation(gId2,
                                                      Group.Type.SELECT),
            GroupOperation.createAddGroupOperation(createdGroup.id(),
                                                   Group.Type.SELECT,
                                                   createdGroup.buckets()));
    if (deviceId.equals(DID)) {
        internalProvider.validate(deviceId, expectedGroupOps);
    } else {
        this.validate(deviceId, expectedGroupOps);
    }
}
 
Example 15
Source File: PollingAlarmProviderTest.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isAvailable(DeviceId did) {
    return did.equals(DEVICE_ID);
}
 
Example 16
Source File: McastHandler.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Gets a path from src to dst.
 * If a path was allocated before, returns the allocated path.
 * Otherwise, randomly pick one from available paths.
 *
 * @param src source device ID
 * @param dst destination device ID
 * @param mcastIp multicast group
 * @param allPaths paths list
 *
 * @return an optional path from src to dst
 */
private Optional<Path> getPath(DeviceId src, DeviceId dst,
                               IpAddress mcastIp, List<Path> allPaths) {
    if (allPaths == null) {
        allPaths = mcastUtils.getPaths(src, dst, Collections.emptySet());
    }
    if (allPaths.isEmpty()) {
        return Optional.empty();
    }
    // Create a map index of suitability-to-list of paths. For example
    // a path in the list associated to the index 1 shares only one link
    // and it is less suitable of a path belonging to the index 2
    Map<Integer, List<Path>> eligiblePaths = Maps.newHashMap();
    int score;
    // Let's build the multicast tree
    Set<List<Link>> storedPaths = getStoredPaths(mcastIp);
    Set<Link> storedTree = storedPaths.stream()
            .flatMap(Collection::stream).collect(Collectors.toSet());
    log.trace("Stored tree {}", storedTree);
    Set<Link> pathLinks;
    for (Path path : allPaths) {
        if (!src.equals(path.links().get(0).src().deviceId())) {
            continue;
        }
        pathLinks = Sets.newHashSet(path.links());
        score = Sets.intersection(pathLinks, storedTree).size();
        // score defines the index
        if (score > 0) {
            eligiblePaths.compute(score, (index, paths) -> {
                paths = paths == null ? Lists.newArrayList() : paths;
                paths.add(path);
                return paths;
            });
        }
    }
    if (eligiblePaths.isEmpty()) {
        log.trace("No eligiblePath(s) found from {} to {}", src, dst);
        Collections.shuffle(allPaths);
        return allPaths.stream().findFirst();
    }
    // Let's take the best ones
    Integer bestIndex = eligiblePaths.keySet().stream()
            .sorted(Comparator.reverseOrder()).findFirst().orElse(null);
    List<Path> bestPaths = eligiblePaths.get(bestIndex);
    log.trace("{} eligiblePath(s) found from {} to {}",
              bestPaths.size(), src, dst);
    Collections.shuffle(bestPaths);
    return bestPaths.stream().findFirst();
}
 
Example 17
Source File: MappingManagerTest.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public Device getDevice(DeviceId deviceId) {
    return deviceId.equals(BAR_DID) ? BAR_DEV : LISP_DEV;
}
 
Example 18
Source File: TroubleshootManagerTest.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public Iterable<FlowEntry> getFlowEntriesByState(DeviceId deviceId, FlowEntry.FlowEntryState state) {
    if (deviceId.equals(SINGLE_FLOW_DEVICE)) {
        return ImmutableList.of(SINGLE_FLOW_ENTRY);
    } else if (deviceId.equals(DUAL_FLOW_DEVICE)) {
        return ImmutableList.of(FIRST_FLOW_ENTRY, SECOND_FLOW_ENTRY);
    } else if (deviceId.equals(GROUP_FLOW_DEVICE)) {
        return ImmutableList.of(GROUP_FLOW_ENTRY);
    } else if (deviceId.equals(TOPO_FLOW_DEVICE) ||
            deviceId.equals(TOPO_FLOW_2_DEVICE) ||
            deviceId.equals(TOPO_FLOW_3_DEVICE) ||
            deviceId.equals(TOPO_FLOW_4_DEVICE)) {
        return ImmutableList.of(TOPO_SINGLE_FLOW_ENTRY, TOPO_SECOND_INPUT_FLOW_ENTRY);
    } else if (deviceId.equals(TOPO_GROUP_FLOW_DEVICE)) {
        return ImmutableList.of(TOPO_GROUP_FLOW_ENTRY);
    } else if (deviceId.equals(HARDWARE_DEVICE)) {
        return ImmutableList.of(HARDWARE_ETH_FLOW_ENTRY, HARDWARE_FLOW_ENTRY);
    } else if (deviceId.equals(SAME_OUTPUT_FLOW_DEVICE)) {
        return ImmutableList.of(SAME_OUTPUT_FLOW_ENTRY);
    } else if (deviceId.equals(ARP_FLOW_DEVICE)) {
        return ImmutableList.of(ARP_FLOW_ENTRY);
    } else if (deviceId.equals(DUAL_LINK_1)) {
        return ImmutableList.of(DUAL_LINK_1_GROUP_FLOW_ENTRY);
    } else if (deviceId.equals(DUAL_LINK_2)) {
        return ImmutableList.of(DUAL_LINK_1_GROUP_FLOW_ENTRY, DUAL_LINK_2_GROUP_FLOW_ENTRY);
    } else if (deviceId.equals(DUAL_LINK_3)) {
        return ImmutableList.of(DUAL_LINK_3_FLOW_ENTRY, DUAL_LINK_3_FLOW_ENTRY_2);
    } else if (deviceId.equals(DEFERRED_1)) {
        return ImmutableList.of(DEFERRED_FLOW_ENTRY, DEFERRED_CLEAR_FLOW_ENTRY);
    } else if (deviceId.equals(HARDWARE_DEVICE_10)) {
        return ImmutableList.of(HARDWARE_10_FLOW_ENTRY, HARDWARE_10_SECOND_FLOW_ENTRY,
                HARDWARE_10_OUTPUT_FLOW_ENTRY);
    } else if (deviceId.equals(LLDP_FLOW_DEVICE)) {
        return ImmutableList.of(LLDP_FLOW_ENTRY);
    } else if (deviceId.equals(MULTICAST_GROUP_FLOW_DEVICE)) {
        return ImmutableList.of(MULTICAST_GROUP_FLOW_ENTRY);
    } else if (deviceId.equals(NO_BUCKET_DEVICE)) {
        return ImmutableList.of(NO_BUCKET_ENTRY);
    } else if (deviceId.equals(DUAL_HOME_DEVICE_1)) {
        return ImmutableList.of(DUAL_HOME_FLOW_ENTRY);
    } else if (deviceId.equals(DUAL_HOME_DEVICE_2) || deviceId.equals(DUAL_HOME_DEVICE_3)) {
        return ImmutableList.of(DUAL_HOME_OUT_FLOW_ENTRY);
    } else if (deviceId.equals(ACTION_ORDER_DEVICE)) {
        return ImmutableList.of(ACTION_ORDER_FLOW_ENTRY);
    }
    return ImmutableList.of();
}
 
Example 19
Source File: LinkHandler.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Checks validity of link. Examples of invalid links include
 * indirect-links, links between ports on the same switch, and more.
 *
 * @param link the link to be processed
 * @return true if valid link
 */
 boolean isLinkValid(Link link) {
    if (link.type() != Link.Type.DIRECT) {
        // NOTE: A DIRECT link might be transiently marked as INDIRECT
        // if BDDP is received before LLDP. We can safely ignore that
        // until the LLDP is received and the link is marked as DIRECT.
        log.info("Ignore link {}->{}. Link type is {} instead of DIRECT.",
                 link.src(), link.dst(), link.type());
        return false;
    }
    DeviceId srcId = link.src().deviceId();
    DeviceId dstId = link.dst().deviceId();
    if (srcId.equals(dstId)) {
        log.warn("Links between ports on the same switch are not "
                + "allowed .. ignoring link {}", link);
        return false;
    }
    DeviceConfiguration devConfig = srManager.deviceConfiguration;
    if (devConfig == null) {
        log.warn("Cannot check validity of link without device config");
        return true;
    }
    try {
        /*if (!devConfig.isEdgeDevice(srcId)
                && !devConfig.isEdgeDevice(dstId)) {
            // ignore links between spines
            // XXX revisit when handling multi-stage fabrics
            log.warn("Links between spines not allowed...ignoring "
                    + "link {}", link);
            return false;
        }*/
        if (devConfig.isEdgeDevice(srcId)
                && devConfig.isEdgeDevice(dstId)) {
            // ignore links between leaves if they are not pair-links
            // XXX revisit if removing pair-link config or allowing more than
            // one pair-link
            if (devConfig.getPairDeviceId(srcId).equals(dstId)
                    && devConfig.getPairLocalPort(srcId)
                            .equals(link.src().port())
                    && devConfig.getPairLocalPort(dstId)
                            .equals(link.dst().port())) {
                // found pair link - allow it
                return true;
            } else {
                log.warn("Links between leaves other than pair-links are "
                        + "not allowed...ignoring link {}", link);
                return false;
            }
        }
    } catch (DeviceConfigNotFoundException e) {
        // We still want to count the links in seenLinks even though there
        // is no config. So we let it return true
        log.warn("Could not check validity of link {} as subtending devices "
                + "are not yet configured", link);
    }
    return true;
}
 
Example 20
Source File: MyTunnelApp.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Provisions a tunnel between the given source and destination host with
 * the given tunnel ID. The tunnel is established using a randomly picked
 * shortest path based on the given topology snapshot.
 *
 * @param tunId   tunnel ID
 * @param srcHost tunnel source host
 * @param dstHost tunnel destination host
 * @param topo    topology snapshot
 */
private void provisionTunnel(int tunId, Host srcHost, Host dstHost, Topology topo) {

    // Get all shortest paths between switches connected to source and
    // destination hosts.
    DeviceId srcSwitch = srcHost.location().deviceId();
    DeviceId dstSwitch = dstHost.location().deviceId();

    List<Link> pathLinks;
    if (srcSwitch.equals(dstSwitch)) {
        // Source and dest hosts are connected to the same switch.
        pathLinks = Collections.emptyList();
    } else {
        // Compute shortest path.
        Set<Path> allPaths = topologyService.getPaths(topo, srcSwitch, dstSwitch);
        if (allPaths.size() == 0) {
            log.warn("No paths between {} and {}", srcHost.id(), dstHost.id());
            return;
        }
        // If many shortest paths are available, pick a random one.
        pathLinks = pickRandomPath(allPaths).links();
    }

    // Tunnel ingress rules.
    for (IpAddress dstIpAddr : dstHost.ipAddresses()) {
        // In ONOS discovered hosts can have multiple IP addresses.
        // Insert tunnel ingress rule for each IP address.
        // Next switches will forward based only on tunnel ID.
        insertTunnelIngressRule(srcSwitch, dstIpAddr, tunId);
    }

    // Insert tunnel transit rules on all switches in the path, excluded the
    // last one.
    for (Link link : pathLinks) {
        DeviceId sw = link.src().deviceId();
        PortNumber port = link.src().port();
        insertTunnelForwardRule(sw, port, tunId, false);
    }

    // Tunnel egress rule.
    PortNumber egressSwitchPort = dstHost.location().port();
    insertTunnelForwardRule(dstSwitch, egressSwitchPort, tunId, true);

    log.info("** Completed provisioning of tunnel {} (srcHost={} dstHost={})",
             tunId, srcHost.id(), dstHost.id());
}