use of org.onosproject.net.behaviour.ControllerInfo in project onos by opennetworkinglab.
the class DefaultOvsdbClient method getOvsdbBridge.
private OvsdbBridge getOvsdbBridge(Row row, Uuid bridgeUuid) {
DatabaseSchema dbSchema = getDatabaseSchema(DATABASENAME);
Bridge bridge = (Bridge) TableGenerator.getTable(dbSchema, row, OvsdbTable.BRIDGE);
if (bridge == null) {
return null;
}
OvsdbSet datapathIdSet = (OvsdbSet) bridge.getDatapathIdColumn().data();
@SuppressWarnings("unchecked") Set<String> datapathIds = datapathIdSet.set();
if (datapathIds == null || datapathIds.isEmpty()) {
return null;
}
String datapathId = (String) datapathIds.toArray()[0];
String bridgeName = bridge.getName();
if ((datapathId == null) || (bridgeName == null)) {
return null;
}
List<Controller> controllers = getControllers(bridgeUuid);
if (controllers != null) {
List<ControllerInfo> controllerInfos = controllers.stream().map(controller -> new ControllerInfo((String) controller.getTargetColumn().data())).collect(Collectors.toList());
return OvsdbBridge.builder().name(bridgeName).datapathId(datapathId).controllers(controllerInfos).build();
} else {
return OvsdbBridge.builder().name(bridgeName).datapathId(datapathId).build();
}
}
use of org.onosproject.net.behaviour.ControllerInfo in project onos by opennetworkinglab.
the class ServerControllerConfig method getControllers.
@Override
public List<ControllerInfo> getControllers() {
List<ControllerInfo> controllers = Lists.newArrayList();
DeviceId deviceId = getDeviceId();
checkNotNull(deviceId, MSG_DEVICE_ID_NULL);
MastershipService mastershipService = getHandler().get(MastershipService.class);
checkNotNull(mastershipService, MSG_MASTERSHIP_NULL);
if (!mastershipService.isLocalMaster(deviceId)) {
log.warn("I am not master for {}. " + "Please use master {} to get controllers for this device", deviceId, mastershipService.getMasterFor(deviceId));
return controllers;
}
// Hit the path that provides the server's controllers
InputStream response = null;
try {
response = getController().get(deviceId, URL_CONTROLLERS_GET, JSON);
} catch (ProcessingException pEx) {
log.error("Failed to get controllers of device: {}", deviceId);
return controllers;
}
// Load the JSON into objects
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> jsonMap = null;
JsonNode jsonNode = null;
ObjectNode objNode = null;
try {
jsonMap = mapper.readValue(response, Map.class);
jsonNode = mapper.convertValue(jsonMap, JsonNode.class);
objNode = (ObjectNode) jsonNode;
} catch (IOException ioEx) {
log.error("Failed to get controllers of device: {}", deviceId);
return controllers;
}
if (jsonMap == null) {
log.error("Failed to get controllers of device: {}", deviceId);
return controllers;
}
// Fetch controllers' array
JsonNode ctrlNode = objNode.path(PARAM_CTRL);
for (JsonNode cn : ctrlNode) {
ObjectNode ctrlObjNode = (ObjectNode) cn;
// Get the attributes of a controller
String ctrlIpStr = get(cn, PARAM_CTRL_IP);
int ctrlPort = ctrlObjNode.path(PARAM_CTRL_PORT).asInt();
String ctrlType = get(cn, PARAM_CTRL_TYPE);
// Implies no controller
if (ctrlIpStr.isEmpty()) {
continue;
}
// Check data format and range
IpAddress ctrlIp = null;
try {
ctrlIp = IpAddress.valueOf(ctrlIpStr);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException(e);
}
if ((ctrlPort < 0) || (ctrlPort > TpPort.MAX_PORT)) {
final String msg = "Invalid controller port: " + ctrlPort;
throw new IllegalArgumentException(msg);
}
controllers.add(new ControllerInfo(ctrlIp, ctrlPort, ctrlType));
}
return controllers;
}
use of org.onosproject.net.behaviour.ControllerInfo in project onos by opennetworkinglab.
the class XmlConfigParserTest method basics.
@Test
public void basics() throws IOException {
InputStream stream = getClass().getResourceAsStream("/testConfig.xml");
List<ControllerInfo> controllers = XmlConfigParser.parseStreamControllers(XmlConfigParser.loadXml(stream));
assertTrue(controllers.get(0).equals(new ControllerInfo(IpAddress.valueOf("10.128.12.1"), 6653, "tcp")));
assertTrue(controllers.get(1).equals(new ControllerInfo(IpAddress.valueOf("10.128.12.2"), 6654, "tcp")));
}
use of org.onosproject.net.behaviour.ControllerInfo in project onos by opennetworkinglab.
the class XmlConfigParserTest method controllersConfig.
@Test
public void controllersConfig() {
InputStream streamOrig = getClass().getResourceAsStream("/testConfig.xml");
InputStream streamCfg = XmlConfigParser.class.getResourceAsStream("/controllers.xml");
String config = XmlConfigParser.createControllersConfig(XmlConfigParser.loadXml(streamCfg), XmlConfigParser.loadXml(streamOrig), "running", "merge", "create", new ArrayList<>(Arrays.asList(new ControllerInfo(IpAddress.valueOf("192.168.1.1"), 5000, "tcp"))));
assertTrue(config.contains("192.168.1.1"));
assertTrue(config.contains("tcp"));
assertTrue(config.contains("5000"));
}
use of org.onosproject.net.behaviour.ControllerInfo in project onos by opennetworkinglab.
the class XmlConfigParser method parseStreamControllers.
public static List<ControllerInfo> parseStreamControllers(HierarchicalConfiguration cfg) {
List<ControllerInfo> controllers = new ArrayList<>();
List<HierarchicalConfiguration> fields = cfg.configurationsAt("data.capable-switch." + "logical-switches." + "switch.controllers.controller");
for (HierarchicalConfiguration sub : fields) {
controllers.add(new ControllerInfo(IpAddress.valueOf(sub.getString("ip-address")), Integer.parseInt(sub.getString("port")), sub.getString("protocol")));
}
return controllers;
}
Aggregations