use of org.onosproject.net.behaviour.ControllerInfo in project onos by opennetworkinglab.
the class JuniperUtils method getOpenFlowControllersFromConfig.
public static List<ControllerInfo> getOpenFlowControllersFromConfig(HierarchicalConfiguration cfg) {
List<ControllerInfo> controllers = new ArrayList<>();
String ipKey = "configuration.protocols.openflow.mode.ofagent-mode.controller.ip";
if (!cfg.configurationsAt(ipKey).isEmpty()) {
List<HierarchicalConfiguration> ipNodes = cfg.configurationsAt(ipKey);
ipNodes.forEach(ipNode -> {
int port = 0;
String proto = UNKNOWN;
HierarchicalConfiguration protocolNode = ipNode.configurationAt(PROTOCOL);
HierarchicalConfiguration tcpNode = protocolNode.configurationAt(TCP);
if (!tcpNode.isEmpty()) {
String portString = tcpNode.getString(PORT);
if (portString != null && !portString.isEmpty()) {
port = Integer.parseInt(portString);
}
proto = TCP;
}
String ipaddress = ipNode.getString(NAME);
if (ipaddress == null) {
ipaddress = UNKNOWN;
}
if (ipaddress.equals(UNKNOWN) || proto.equals(UNKNOWN) || port == 0) {
log.error("Controller infomation is invalid. Skip this controller node." + " ipaddress: {}, proto: {}, port: {}", ipaddress, proto, port);
return;
}
controllers.add(new ControllerInfo(IpAddress.valueOf(ipaddress), port, proto));
});
} else {
log.error("Controller not present");
}
return controllers;
}
use of org.onosproject.net.behaviour.ControllerInfo in project onos by opennetworkinglab.
the class NetconfControllerConfig method getControllers.
@Override
public List<ControllerInfo> getControllers() {
DriverHandler handler = handler();
NetconfController controller = handler.get(NetconfController.class);
MastershipService mastershipService = handler.get(MastershipService.class);
DeviceId deviceId = handler.data().deviceId();
Preconditions.checkNotNull(controller, "Netconf controller is null");
List<ControllerInfo> controllers = new ArrayList<>();
if (mastershipService.isLocalMaster(deviceId)) {
try {
String reply = controller.getNetconfDevice(deviceId).getSession().getConfig(DatastoreId.RUNNING);
log.debug("Reply XML {}", reply);
controllers.addAll(XmlConfigParser.parseStreamControllers(XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8)))));
} catch (NetconfException e) {
log.error("Cannot communicate with device {} ", deviceId, e);
}
} else {
log.warn("I'm not master for {} please use master, {} to execute command", deviceId, mastershipService.getMasterFor(deviceId));
}
return controllers;
}
use of org.onosproject.net.behaviour.ControllerInfo in project onos by opennetworkinglab.
the class FujitsuVoltControllerConfig method getControllers.
@Override
public List<ControllerInfo> getControllers() {
DriverHandler handler = handler();
NetconfController controller = handler.get(NetconfController.class);
MastershipService mastershipService = handler.get(MastershipService.class);
DeviceId ncDeviceId = handler.data().deviceId();
checkNotNull(controller, "Netconf controller is null");
List<ControllerInfo> controllers = new ArrayList<>();
if (mastershipService.isLocalMaster(ncDeviceId)) {
try {
StringBuilder request = new StringBuilder();
request.append(VOLT_NE_OPEN + VOLT_NE_NAMESPACE + ">\n");
request.append(buildEmptyTag(VOLT_OFCONFIG));
request.append(VOLT_NE_CLOSE);
String reply;
reply = controller.getDevicesMap().get(ncDeviceId).getSession().get(request.toString(), REPORT_ALL);
log.debug("Reply XML {}", reply);
controllers.addAll(parseStreamVoltControllers(XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8)))));
} catch (NetconfException e) {
log.error("Cannot communicate to device {} ", ncDeviceId);
}
} else {
log.warn("I'm not master for {} please use master, {} to execute command", ncDeviceId, mastershipService.getMasterFor(ncDeviceId));
}
return ImmutableList.copyOf(controllers);
}
use of org.onosproject.net.behaviour.ControllerInfo in project onos by opennetworkinglab.
the class DellRestOpenFlowControllerConfig method getControllerCommands.
// Get controller commands for maximum first 2 controllers
private List<String> getControllerCommands(List<ControllerInfo> controllers) {
List<String> controllerCommands = new ArrayList<>();
for (int controllerNum = 0; controllerNum < MAX_CONTROLLERS; ++controllerNum) {
if (controllers.size() > controllerNum) {
ControllerInfo controllerInfo = controllers.get(controllerNum);
// Only "tcp" type is supported
if (controllerInfo.type().equals(TCP)) {
String ip = controllerInfo.ip().toString();
int port = controllerInfo.port();
controllerCommands.add(String.format(SET_CONTROLLER, controllerNum + 1, ip, port));
} else {
log.warn("Controller type can only be 'tcp'");
controllerCommands.add(String.format(NO_CONTROLLER, controllerNum + 1));
}
} else {
// remove existing controller
controllerCommands.add(String.format(NO_CONTROLLER, controllerNum + 1));
}
}
return controllerCommands;
}
use of org.onosproject.net.behaviour.ControllerInfo in project onos by opennetworkinglab.
the class ControllerConfigAristaImpl method getControllers.
@Override
public List<ControllerInfo> getControllers() {
log.debug("Arista get Controllers");
List<ControllerInfo> controllers = new ArrayList<>();
Optional<JsonNode> res = AristaUtils.retrieveCommandResult(handler(), SHOW_CONTROLLER_CMD);
if (res == null) {
log.warn("There is no connected controller.");
return controllers;
}
JsonNode controllerInfo = res.get().findValue(CONTROLLER_INFO);
Iterator<JsonNode> controlleriter = controllerInfo.iterator();
while (controlleriter.hasNext()) {
JsonNode temp1 = controlleriter.next();
if (temp1.has(CONTROLLER_ADDR)) {
JsonNode controllerAddr = temp1.get(CONTROLLER_ADDR);
if (controllerAddr.has(CONTROLLER_IP) && controllerAddr.has(CONTROLLER_PORT)) {
String ip = controllerAddr.get(CONTROLLER_IP).asText();
int port = controllerAddr.get(CONTROLLER_PORT).asInt();
ControllerInfo info = new ControllerInfo(IpAddress.valueOf(ip), port, PROTOCOL_TCP);
controllers.add(info);
log.debug("Controller Information {}", info.target());
}
}
}
return ImmutableList.copyOf(controllers);
}
Aggregations