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);
}
}
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());
}
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;
}
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;
}
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());
}
Aggregations