Search in sources :

Example 26 with DriverHandler

use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.

the class DeviceInterfaceRemoveCommand method doExecute.

@Override
protected void doExecute() {
    DriverService service = get(DriverService.class);
    DeviceId deviceId = DeviceId.deviceId(uri);
    DriverHandler h = service.createHandler(deviceId);
    InterfaceConfig interfaceConfig = h.behaviour(InterfaceConfig.class);
    if (trunkMode && !accessMode && !rateLimit) {
        // Trunk mode for VLAN to be removed.
        removeTrunkModeFromIntf(interfaceConfig);
    } else if (accessMode && !trunkMode && !rateLimit) {
        // Access mode for VLAN to be removed.
        removeAccessModeFromIntf(interfaceConfig);
    } else if (rateLimit && !trunkMode && !accessMode) {
        // Rate limit to be removed.
        removeRateLimitFromIntf(interfaceConfig);
    } else {
        // Option has not been correctly set.
        print(ONE_ACTION_ALLOWED);
    }
}
Also used : InterfaceConfig(org.onosproject.net.behaviour.InterfaceConfig) DeviceId(org.onosproject.net.DeviceId) DriverHandler(org.onosproject.net.driver.DriverHandler) DriverService(org.onosproject.net.driver.DriverService)

Example 27 with DriverHandler

use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.

the class DeviceSetControllersCommand method doExecute.

@Override
protected void doExecute() {
    if (controllersListStrings == null && !removeCont && !removeAll) {
        print("No controller are given, skipping.");
        return;
    }
    if (controllersListStrings != null) {
        Arrays.asList(controllersListStrings).forEach(cInfoString -> {
            ControllerInfo controllerInfo = parseCInfoString(cInfoString);
            if (controllerInfo != null) {
                controllers.add(controllerInfo);
            }
        });
    }
    DriverService service = get(DriverService.class);
    deviceId = DeviceId.deviceId(uri);
    DriverHandler h = service.createHandler(deviceId);
    ControllerConfig config = h.behaviour(ControllerConfig.class);
    print("before:");
    config.getControllers().forEach(c -> print(c.target()));
    try {
        if (removeAll) {
            if (!controllers.isEmpty()) {
                print("Controllers list should be empty to remove all controllers");
            } else {
                List<ControllerInfo> controllersToRemove = config.getControllers();
                controllersToRemove.forEach(c -> print("Will remove " + c.target()));
                config.removeControllers(controllersToRemove);
            }
        } else {
            if (controllers.isEmpty()) {
                print("Controllers list is empty, cannot set/remove empty controllers");
            } else {
                if (removeCont) {
                    print("Will remove specified controllers");
                    config.removeControllers(controllers);
                } else {
                    print("Will add specified controllers");
                    config.setControllers(controllers);
                }
            }
        }
    } catch (NullPointerException e) {
        print("No Device with requested parameters {} ", uri);
    }
    print("after:");
    config.getControllers().forEach(c -> print(c.target()));
    print("size %d", config.getControllers().size());
}
Also used : ControllerConfig(org.onosproject.net.behaviour.ControllerConfig) DriverHandler(org.onosproject.net.driver.DriverHandler) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo) DriverService(org.onosproject.net.driver.DriverService)

Example 28 with DriverHandler

use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.

the class SelectGroupHandler method buildNiciraExtenstion.

/**
 * Builds Nicira extension for tagging remoteIp of vxlan.
 *
 * @param id device id of vxlan source device
 * @param hostIp remote ip of vxlan destination device
 * @return NiciraExtension Treatment
 */
private ExtensionTreatment buildNiciraExtenstion(DeviceId id, Ip4Address hostIp) {
    Driver driver = driverService.getDriver(id);
    DriverHandler driverHandler = new DefaultDriverHandler(new DefaultDriverData(driver, id));
    ExtensionTreatmentResolver resolver = driverHandler.behaviour(ExtensionTreatmentResolver.class);
    ExtensionTreatment extensionInstruction = resolver.getExtensionInstruction(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type());
    try {
        extensionInstruction.setPropertyValue(TUNNEL_DESTINATION, hostIp);
    } catch (ExtensionPropertyException e) {
        log.error("Error setting Nicira extension setting {}", e);
    }
    return extensionInstruction;
}
Also used : DefaultDriverHandler(org.onosproject.net.driver.DefaultDriverHandler) DefaultDriverHandler(org.onosproject.net.driver.DefaultDriverHandler) DriverHandler(org.onosproject.net.driver.DriverHandler) Driver(org.onosproject.net.driver.Driver) ExtensionTreatmentResolver(org.onosproject.net.behaviour.ExtensionTreatmentResolver) ExtensionTreatment(org.onosproject.net.flow.instructions.ExtensionTreatment) ExtensionPropertyException(org.onosproject.net.flow.instructions.ExtensionPropertyException) DefaultDriverData(org.onosproject.net.driver.DefaultDriverData)

Example 29 with DriverHandler

use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.

the class RulePopulatorUtil method buildCtExtensionSelector.

/**
 * Builds OVS ConnTrack matches.
 *
 * @param driverService driver service
 * @param deviceId device ID
 * @param ctState connection tracking sate masking value
 * @param ctSateMask connection tracking sate masking value
 * @return OVS ConnTrack extension match
 */
public static ExtensionSelector buildCtExtensionSelector(DriverService driverService, DeviceId deviceId, long ctState, long ctSateMask) {
    DriverHandler handler = driverService.createHandler(deviceId);
    ExtensionSelectorResolver esr = handler.behaviour(ExtensionSelectorResolver.class);
    ExtensionSelector extensionSelector = esr.getExtensionSelector(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_STATE.type());
    try {
        extensionSelector.setPropertyValue(CT_STATE, ctState);
        extensionSelector.setPropertyValue(CT_STATE_MASK, ctSateMask);
    } catch (Exception e) {
        log.error("Failed to set nicira match CT state because of {}", e);
        return null;
    }
    return extensionSelector;
}
Also used : ExtensionSelector(org.onosproject.net.flow.criteria.ExtensionSelector) DriverHandler(org.onosproject.net.driver.DriverHandler) ExtensionSelectorResolver(org.onosproject.net.behaviour.ExtensionSelectorResolver) ExtensionPropertyException(org.onosproject.net.flow.instructions.ExtensionPropertyException)

Example 30 with DriverHandler

use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.

the class CiscoNxosDeviceDescription method discoverDeviceDetails.

@Override
public DeviceDescription discoverDeviceDetails() {
    DriverHandler handler = handler();
    RestSBController controller = checkNotNull(handler.get(RestSBController.class));
    DeviceId deviceId = handler.data().deviceId();
    ArrayList<String> cmd = new ArrayList<>();
    cmd.add(SHOW_VERSION_CMD);
    String req = NxApiRequest.generate(cmd, NxApiRequest.CommandType.CLI);
    String response = NxApiRequest.post(controller, deviceId, req);
    String mrf = UNKNOWN;
    String hwVer = UNKNOWN;
    String swVer = UNKNOWN;
    String serialNum = UNKNOWN;
    try {
        ObjectMapper om = new ObjectMapper();
        JsonNode json = om.readTree(response);
        JsonNode body = json.findValue("body");
        if (body != null) {
            mrf = body.get(MANUFACTURER).asText();
            hwVer = body.get(CHASSIS_ID).asText();
            swVer = body.get(KICKSTART_VER).asText();
        }
    } catch (IOException e) {
        log.error("Failed to to retrieve Device Information {}", e);
    }
    DeviceService deviceService = checkNotNull(handler().get(DeviceService.class));
    Device device = deviceService.getDevice(deviceId);
    return new DefaultDeviceDescription(device.id().uri(), Device.Type.SWITCH, mrf, hwVer, swVer, serialNum, new ChassisId(), (SparseAnnotations) device.annotations());
}
Also used : ChassisId(org.onlab.packet.ChassisId) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) ArrayList(java.util.ArrayList) DeviceService(org.onosproject.net.device.DeviceService) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) RestSBController(org.onosproject.protocol.rest.RestSBController) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DriverHandler(org.onosproject.net.driver.DriverHandler) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

DriverHandler (org.onosproject.net.driver.DriverHandler)104 DeviceId (org.onosproject.net.DeviceId)46 DriverService (org.onosproject.net.driver.DriverService)22 NetconfController (org.onosproject.netconf.NetconfController)22 NetconfException (org.onosproject.netconf.NetconfException)22 MastershipService (org.onosproject.mastership.MastershipService)20 ArrayList (java.util.ArrayList)12 DefaultDriverHandler (org.onosproject.net.driver.DefaultDriverHandler)12 ItemNotFoundException (org.onlab.util.ItemNotFoundException)9 DeviceService (org.onosproject.net.device.DeviceService)9 OvsdbClientService (org.onosproject.ovsdb.controller.OvsdbClientService)9 DefaultDriverData (org.onosproject.net.driver.DefaultDriverData)8 Driver (org.onosproject.net.driver.Driver)8 Test (org.junit.Test)7 ControllerInfo (org.onosproject.net.behaviour.ControllerInfo)6 RestSBController (org.onosproject.protocol.rest.RestSBController)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 PolicerConfigurable (org.onosproject.net.behaviour.trafficcontrol.PolicerConfigurable)5 PolicerId (org.onosproject.net.behaviour.trafficcontrol.PolicerId)5