Java Code Examples for org.onosproject.net.Device#id()

The following examples show how to use org.onosproject.net.Device#id() . 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: FlowStatisticManager.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public Map<ConnectPoint, List<FlowEntryWithLoad>> loadTopnByType(Device device,
                                                               FlowEntry.FlowLiveType liveType,
                                                               Instruction.Type instType,
                                                               int topn) {
    checkPermission(STATISTIC_READ);

    Map<ConnectPoint, List<FlowEntryWithLoad>> allLoad =
                                    new TreeMap<>(Comparators.CONNECT_POINT_COMPARATOR);

    if (device == null) {
        return allLoad;
    }

    List<Port> ports = new ArrayList<>(deviceService.getPorts(device.id()));

    for (Port port : ports) {
        ConnectPoint cp = new ConnectPoint(device.id(), port.number());
        List<FlowEntryWithLoad> fel = loadTopnPortInternal(cp, liveType, instType, topn);
        allLoad.put(cp, fel);
    }

    return allLoad;
}
 
Example 2
Source File: DeviceViewMessageHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
private void populateRow(TableModel.Row row, Device dev,
                         DeviceService ds, MastershipService ms) {
    DeviceId id = dev.id();
    boolean available = ds.isAvailable(id);
    String iconId = available ? ICON_ID_ONLINE : ICON_ID_OFFLINE;

    row.cell(ID, id)
        .cell(NAME, deviceName(dev))
        .cell(AVAILABLE, available)
        .cell(AVAILABLE_IID, iconId)
        .cell(TYPE_IID, getTypeIconId(dev))
        .cell(MFR, dev.manufacturer())
        .cell(HW, dev.hwVersion())
        .cell(SW, dev.swVersion())
        .cell(PROTOCOL, deviceProtocol(dev))
        .cell(NUM_PORTS, ds.getPorts(id).size())
        .cell(MASTER_ID, ms.getMasterFor(id));
}
 
Example 3
Source File: AbstractTopoModelTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a default host connected at the given edge device and port. Note
 * that an identifying hex character ("a" - "f") should be supplied. This
 * will be included in the MAC address of the host (and equivalent value
 * as last byte in IP address).
 *
 * @param device  edge device
 * @param port    port number
 * @param hexChar identifying hex character
 * @return host connected at that location
 */
protected static Host createHost(Device device, int port, String hexChar) {
    DeviceId deviceId = device.id();
    String devNum = deviceId.toString().substring(1);

    MacAddress mac = MacAddress.valueOf(HOST_MAC_PREFIX + devNum + hexChar);
    HostId hostId = hostId(String.format("%s/-1", mac));

    int ipByte = Integer.valueOf(hexChar, 16);
    if (ipByte < 10 || ipByte > 15) {
        throw new IllegalArgumentException("hexChar must be a-f");
    }
    HostLocation loc = new HostLocation(deviceId, portNumber(port), 0);

    IpAddress ip = ip("10." + devNum + ".0." + ipByte);

    return new DefaultHost(ProviderId.NONE, hostId, mac, VlanId.NONE,
            loc, ImmutableSet.of(ip));
}
 
Example 4
Source File: ScaleTestManager.java    From onos with Apache License 2.0 6 votes vote down vote up
private void adjustFlows() {
    int deviceCount = deviceService.getAvailableDeviceCount();
    if (deviceCount == 0) {
        return;
    }

    int flowsPerDevice = flowCount / deviceCount;
    for (Device device : deviceService.getAvailableDevices()) {
        DeviceId id = device.id();
        if (deviceService.getRole(id) != MastershipRole.MASTER ||
                flowsPerDevice == 0) {
            continue;
        }

        int currentFlowCount = flowRuleService.getFlowRuleCount(id);
        if (flowsPerDevice > currentFlowCount) {
            addMoreFlows(flowsPerDevice, device, id, currentFlowCount);

        } else if (flowsPerDevice < currentFlowCount) {
            removeExcessFlows(flowsPerDevice, id, currentFlowCount);
        }
    }
}
 
Example 5
Source File: DefaultOpenstackNodeHandlerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
private static OpenstackNode createNode(String hostname,
                                        OpenstackNode.NodeType type,
                                        Device intgBridge,
                                        IpAddress ipAddr,
                                        NodeState state,
                                        Set<OpenstackPhyInterface> phyIntfs,
                                        Set<ControllerInfo> controllers) {
    return new TestOpenstackNode(
            hostname,
            type,
            intgBridge.id(),
            ipAddr,
            ipAddr,
            null, null, state, phyIntfs, controllers,
            null, null, null, null);
}
 
Example 6
Source File: FlowStatisticManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public List<FlowEntryWithLoad> loadAllByType(Device device, PortNumber pNumber,
                                           FlowEntry.FlowLiveType liveType,
                                           Instruction.Type instType) {
    checkPermission(STATISTIC_READ);

    ConnectPoint cp = new ConnectPoint(device.id(), pNumber);
    return loadAllPortInternal(cp, liveType, instType);
}
 
Example 7
Source File: DefaultOpenstackNodeHandlerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
private static OpenstackNode createGatewayNode(String hostname,
                                        OpenstackNode.NodeType type,
                                        Device intgBridge,
                                        IpAddress ipAddr,
                                        String uplinkPort,
                                        NodeState state) {
    return new TestOpenstackNode(
            hostname,
            type,
            intgBridge.id(),
            ipAddr,
            ipAddr,
            null, uplinkPort, state, null, null, null, null, null,
            null);
}
 
Example 8
Source File: VtnData.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Get the ControllerId from the device .
 *
 * @param device Device
 * @param devices Devices
 * @return Controller Id
 */
public static DeviceId getControllerId(Device device,
                                       Iterable<Device> devices) {
    for (Device d : devices) {
        if (d.type() == Device.Type.CONTROLLER && d.id().toString()
                .contains(getControllerIpOfSwitch(device))) {
            return d.id();
        }
    }
    log.info("Can not find controller for device : {}", device.id());
    return null;
}
 
Example 9
Source File: FlowStatisticManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public SummaryFlowEntryWithLoad loadSummary(Device device, PortNumber pNumber) {
    checkPermission(STATISTIC_READ);

    ConnectPoint cp = new ConnectPoint(device.id(), pNumber);
    return loadSummaryPortInternal(cp);
}
 
Example 10
Source File: DefaultGraphDescription.java    From onos with Apache License 2.0 5 votes vote down vote up
private ImmutableSet<TopologyVertex> buildVertexes(Iterable<Device> devices) {
    ImmutableSet.Builder<TopologyVertex> vertexes = ImmutableSet.builder();
    for (Device device : devices) {
        TopologyVertex vertex = new DefaultTopologyVertex(device.id());
        vertexes.add(vertex);
        vertexesById.put(vertex.deviceId(), vertex);
    }
    return vertexes.build();
}
 
Example 11
Source File: UiDevice.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new UI device.
 *
 * @param topology parent topology
 * @param device   backing device
 */
public UiDevice(UiTopology topology, Device device) {
    checkNotNull(device, DEVICE_CANNOT_BE_NULL);
    this.topology = topology;
    this.deviceId = device.id();
    this.regionId = RegionId.regionId(UiRegion.NULL_NAME);
}
 
Example 12
Source File: PcepTunnelProvider.java    From onos with Apache License 2.0 5 votes vote down vote up
private DeviceId getDevice(PccId pccId) {
    // Get lsrId of the PCEP client from the PCC ID. Session info is based on lsrID.
    IpAddress lsrId = pccId.ipAddress();
    String lsrIdentifier = String.valueOf(lsrId);

    // Find PCC deviceID from lsrId stored as annotations
    Iterable<Device> devices = deviceService.getAvailableDevices();
    for (Device dev : devices) {
        if (dev.annotations().value(AnnotationKeys.TYPE).equals("L3")
                && dev.annotations().value(LSRID).equals(lsrIdentifier)) {
            return dev.id();
        }
    }
    return null;
}
 
Example 13
Source File: DcsBasedTapiTopologyManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void addDevice(Device device) {
    log.debug("Add device: {}", device);
    DeviceId deviceId = device.id();
    if (tapiResolver.hasNodeRef(deviceId)) {
        return;
    }
    TapiNodeHandler.create()
            .setTopologyUuid(topology.uuid())
            .setDeviceId(deviceId).add();
}
 
Example 14
Source File: NullPacketProvider.java    From onos with Apache License 2.0 5 votes vote down vote up
private void sendEvent(Device device) {
    // Make it look like things came from ports attached to hosts
    eth.setSourceMACAddress("00:00:00:10:00:0" + SRC_HOST)
            .setDestinationMACAddress("00:00:00:10:00:0" + DST_HOST);
    InboundPacket inPkt = new DefaultInboundPacket(
            new ConnectPoint(device.id(), PortNumber.portNumber(SRC_HOST)),
            eth, ByteBuffer.wrap(eth.serialize()));
    providerService.processPacket(new NullPacketContext(inPkt, null));
}
 
Example 15
Source File: PcepClientControllerImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Releases node label of a specific device.
 *
 * @param specificDevice this device label and lsr-id information will be
 *            released in other existing devices
 */
public void releaseNodeLabel(Device specificDevice) {
    checkNotNull(specificDevice, DEVICE_NULL);

    DeviceId deviceId = specificDevice.id();

    // Retrieve lsrId of a specific device
    if (specificDevice.annotations() == null) {
        log.debug("Device {} does not have annotations.", specificDevice.toString());
        return;
    }

    String lsrId = specificDevice.annotations().value(LSRID);
    if (lsrId == null) {
        log.debug("Unable to retrieve lsr-id of a device {}.", specificDevice.toString());
        return;
    }

    // Get capability config from netconfig
    DeviceCapability cfg = netCfgService.getConfig(DeviceId.deviceId(lsrId), DeviceCapability.class);
    if (cfg == null) {
        log.error("Unable to find corresponding capabilty for a lsrd {} from NetConfig.", lsrId);
        return;
    }

    // Check whether device has SR-TE Capability
    if (cfg.labelStackCap()) {
        if (!srTeHandler.releaseNodeLabel(deviceId, lsrId)) {
            log.error("Unable to release node label for a device id {}.", deviceId.toString());
        }
    }
}
 
Example 16
Source File: FlowStatisticManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public List<FlowEntryWithLoad> loadTopnByType(Device device, PortNumber pNumber,
                                            FlowEntry.FlowLiveType liveType,
                                            Instruction.Type instType,
                                            int topn) {
    checkPermission(STATISTIC_READ);

    ConnectPoint cp = new ConnectPoint(device.id(), pNumber);
    return loadTopnPortInternal(cp, liveType, instType, topn);
}
 
Example 17
Source File: ModelCache.java    From onos with Apache License 2.0 5 votes vote down vote up
void removeDevice(Device device) {
    DeviceId id = device.id();
    UiDevice uiDevice = uiTopology.findDevice(id);
    if (uiDevice != null) {
        uiTopology.remove(uiDevice);
        postEvent(DEVICE_REMOVED, uiDevice, MEMO_REMOVED);
    } else {
        log.warn(E_NO_ELEMENT, "device", id);
    }
}
 
Example 18
Source File: ModelCache.java    From onos with Apache License 2.0 5 votes vote down vote up
void addOrUpdateDevice(Device device) {
    DeviceId id = device.id();
    String memo = MEMO_UPDATED;
    UiDevice uiDevice = uiTopology.findDevice(id);
    if (uiDevice == null) {
        uiDevice = addNewDevice(device);
        memo = MEMO_ADDED;
    } else {
        updateDevice(uiDevice);
    }

    postEvent(DEVICE_ADDED_OR_UPDATED, uiDevice, memo);
}
 
Example 19
Source File: McastHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
private void processPortUpdateInternal(Device affectedDevice, Port affectedPort) {
    // Clean the filtering obj store. Edge port case.
    lastMcastChange.set(Instant.now());
    ConnectPoint portDown = new ConnectPoint(affectedDevice.id(), affectedPort.number());
    if (!affectedPort.isEnabled()) {
        log.info("Processing port down {}", portDown);
        updateFilterObjStoreByPort(portDown);
    }
}
 
Example 20
Source File: DefaultRoutingHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Revoke rules of given subnet in all edge switches.
 *
 * @param subnets subnet being removed
 * @return true if succeed
 */
protected boolean revokeSubnet(Set<IpPrefix> subnets) {
    DeviceId targetSw;
    List<Future<Boolean>> futures = Lists.newArrayList();
    for (Device sw : srManager.deviceService.getAvailableDevices()) {
        targetSw = sw.id();
        if (shouldProgram(targetSw)) {
            futures.add(routePopulators.submit(new RevokeSubnet(targetSw, subnets)));
        } else {
            futures.add(CompletableFuture.completedFuture(true));
        }
    }
    // check the execution of each job
    return checkJobs(futures);
}