Search in sources :

Example 6 with DeviceService

use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.

the class VirtualNetworkFlowRuleManager method getFlowRulesByGroupId.

@Override
public Iterable<FlowRule> getFlowRulesByGroupId(ApplicationId appId, short groupId) {
    DeviceService deviceService = manager.get(networkId(), DeviceService.class);
    Set<FlowRule> matches = Sets.newHashSet();
    long toLookUp = ((long) appId.id() << 16) | groupId;
    for (Device d : deviceService.getDevices()) {
        for (FlowEntry flowEntry : store.getFlowEntries(networkId(), d.id())) {
            if ((flowEntry.id().value() >>> 32) == toLookUp) {
                matches.add(flowEntry);
            }
        }
    }
    return matches;
}
Also used : Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) FlowRule(org.onosproject.net.flow.FlowRule) FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry)

Example 7 with DeviceService

use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.

the class VirtualNetworkFlowRuleManager method getFlowEntriesById.

@Override
public Iterable<FlowEntry> getFlowEntriesById(ApplicationId id) {
    DeviceService deviceService = manager.get(networkId(), DeviceService.class);
    Set<FlowEntry> flowEntries = Sets.newHashSet();
    for (Device d : deviceService.getDevices()) {
        for (FlowEntry flowEntry : store.getFlowEntries(networkId(), d.id())) {
            if (flowEntry.appId() == id.id()) {
                flowEntries.add(flowEntry);
            }
        }
    }
    return flowEntries;
}
Also used : Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry)

Example 8 with DeviceService

use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.

the class EncodeInstructionCodecHelper method encodeExtension.

/**
 * Encodes a extension instruction.
 *
 * @param result json node that the instruction attributes are added to
 */
private void encodeExtension(ObjectNode result) {
    final Instructions.ExtensionInstructionWrapper extensionInstruction = (Instructions.ExtensionInstructionWrapper) instruction;
    DeviceId deviceId = extensionInstruction.deviceId();
    ServiceDirectory serviceDirectory = new DefaultServiceDirectory();
    DeviceService deviceService = serviceDirectory.get(DeviceService.class);
    Device device = deviceService.getDevice(deviceId);
    if (device == null) {
        throw new IllegalArgumentException("Device not found");
    }
    if (device.is(ExtensionTreatmentCodec.class)) {
        // for extension instructions, encoding device id is needed for the corresponding decoder
        result.put("deviceId", deviceId.toString());
        ExtensionTreatmentCodec treatmentCodec = device.as(ExtensionTreatmentCodec.class);
        ObjectNode node = treatmentCodec.encode(extensionInstruction.extensionInstruction(), context);
        result.set(InstructionCodec.EXTENSION, node);
    } else {
        throw new IllegalArgumentException("There is no codec to encode extension for device " + deviceId.toString());
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceId(org.onosproject.net.DeviceId) DefaultServiceDirectory(org.onlab.osgi.DefaultServiceDirectory) ServiceDirectory(org.onlab.osgi.ServiceDirectory) Device(org.onosproject.net.Device) ExtensionTreatmentCodec(org.onosproject.net.flow.ExtensionTreatmentCodec) DeviceService(org.onosproject.net.device.DeviceService) Instructions(org.onosproject.net.flow.instructions.Instructions) DefaultServiceDirectory(org.onlab.osgi.DefaultServiceDirectory)

Example 9 with DeviceService

use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.

the class OpenstackNodeCheckCommand method doExecute.

@Override
protected void doExecute() {
    OpenstackNodeService osNodeService = get(OpenstackNodeService.class);
    DeviceService deviceService = get(DeviceService.class);
    OpenstackNode osNode = osNodeService.node(hostname);
    if (osNode == null) {
        print("Cannot find %s from registered nodes", hostname);
        return;
    }
    if (osNode.type() == CONTROLLER) {
        print("[Openstack Controller Status]");
        OSClient client = getConnectedClient(osNode);
        if (client == null) {
            error("The given keystone info is incorrect to get authorized to openstack");
            print("keystoneConfig=%s", osNode.keystoneConfig());
        }
        if (osNode.keystoneConfig() != null) {
            print("%s keystoneConfig=%s, neutronConfig=%s", osNode.state() == NodeState.COMPLETE && client != null ? MSG_OK : MSG_ERROR, osNode.keystoneConfig(), osNode.neutronConfig());
        } else {
            print("%s keystoneConfig is missing", MSG_ERROR);
        }
    } else {
        print("[Integration Bridge Status]");
        Device device = deviceService.getDevice(osNode.intgBridge());
        Device ovsdbDevice = deviceService.getDevice(osNode.ovsdb());
        if (device != null) {
            print("%s OvsdbDeviceId=%s available=%s", deviceService.isAvailable(ovsdbDevice.id()) ? MSG_OK : MSG_ERROR, ovsdbDevice.id(), deviceService.isAvailable(ovsdbDevice.id()));
            print("%s %s=%s available=%s %s", deviceService.isAvailable(device.id()) ? MSG_OK : MSG_ERROR, INTEGRATION_BRIDGE, device.id(), deviceService.isAvailable(device.id()), device.annotations());
            if (osNode.dataIp() != null) {
                printPortState(deviceService, osNode.intgBridge(), VXLAN_TUNNEL);
                printPortState(deviceService, osNode.intgBridge(), GRE_TUNNEL);
                printPortState(deviceService, osNode.intgBridge(), GENEVE_TUNNEL);
            }
            if (osNode.vlanIntf() != null) {
                printPortState(deviceService, osNode.intgBridge(), osNode.vlanIntf());
            }
            osNode.phyIntfs().forEach(intf -> {
                printPortState(deviceService, osNode.intgBridge(), structurePortName(INTEGRATION_TO_PHYSICAL_PREFIX + intf.network()));
            });
            if (osNode.type() == GATEWAY) {
                printPortState(deviceService, osNode.intgBridge(), osNode.uplinkPort());
            }
        } else {
            print("%s %s=%s is not available", MSG_ERROR, INTEGRATION_BRIDGE, osNode.intgBridge());
        }
    }
}
Also used : OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) OSClient(org.openstack4j.api.OSClient) Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode)

Example 10 with DeviceService

use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.

the class DefaultOpenstackNode method tunnelPortNum.

private PortNumber tunnelPortNum(String tunnelType) {
    if (dataIp == null) {
        return null;
    }
    DeviceService deviceService = DefaultServiceDirectory.getService(DeviceService.class);
    Port port = deviceService.getPorts(intgBridge).stream().filter(p -> p.isEnabled() && Objects.equals(p.annotations().value(PORT_NAME), tunnelType)).findAny().orElse(null);
    return port != null ? port.number() : null;
}
Also used : Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService)

Aggregations

DeviceService (org.onosproject.net.device.DeviceService)187 Device (org.onosproject.net.Device)75 DeviceId (org.onosproject.net.DeviceId)73 Port (org.onosproject.net.Port)59 ConnectPoint (org.onosproject.net.ConnectPoint)42 PortNumber (org.onosproject.net.PortNumber)40 List (java.util.List)30 Collectors (java.util.stream.Collectors)24 Set (java.util.Set)23 AbstractHandlerBehaviour (org.onosproject.net.driver.AbstractHandlerBehaviour)19 Logger (org.slf4j.Logger)19 ArrayList (java.util.ArrayList)18 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)17 Optional (java.util.Optional)17 Test (org.junit.Test)16 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 Collections (java.util.Collections)15 VirtualNetwork (org.onosproject.incubator.net.virtual.VirtualNetwork)15 DriverHandler (org.onosproject.net.driver.DriverHandler)15 Collection (java.util.Collection)14