use of org.onosproject.net.behaviour.ControllerInfo in project onos by opennetworkinglab.
the class YangXmlUtilsTest method getXmlConfigurationFromYangElements.
/**
* Tests getting a multiple object nested configuration via passing the path
* and a list of YangElements containing with the element and desired value.
*
* @throws ConfigurationException
*/
@Test
public void getXmlConfigurationFromYangElements() throws ConfigurationException {
assertNotEquals("Null testConfiguration", new XMLConfiguration(), testCreateConfig);
testCreateConfig.load(getClass().getResourceAsStream("/testYangConfig.xml"));
List<YangElement> elements = new ArrayList<>();
elements.add(new YangElement("capable-switch", ImmutableMap.of("id", "openvswitch")));
elements.add(new YangElement("switch", ImmutableMap.of("id", "ofc-bridge")));
List<ControllerInfo> controllers = ImmutableList.of(new ControllerInfo(IpAddress.valueOf("1.1.1.1"), 1, "tcp"), new ControllerInfo(IpAddress.valueOf("2.2.2.2"), 2, "tcp"));
controllers.forEach(cInfo -> {
elements.add(new YangElement("controller", ImmutableMap.of("id", cInfo.target(), "ip-address", cInfo.ip().toString())));
});
XMLConfiguration cfg = new XMLConfiguration(YangXmlUtils.getInstance().getXmlConfiguration(OF_CONFIG_XML_PATH, elements));
assertEquals("Wrong configuaration", IteratorUtils.toList(testCreateConfig.getKeys()), IteratorUtils.toList(cfg.getKeys()));
assertEquals("Wrong string configuaration", canonicalXml(utils.getString(testCreateConfig)), canonicalXml(utils.getString(cfg)));
}
use of org.onosproject.net.behaviour.ControllerInfo in project onos by opennetworkinglab.
the class XmlConfigParser method createControllersConfig.
public static String createControllersConfig(HierarchicalConfiguration cfg, HierarchicalConfiguration actualCfg, String target, String netconfOperation, String controllerOperation, List<ControllerInfo> controllers) {
// cfg.getKeys().forEachRemaining(key -> System.out.println(key));
cfg.setProperty("edit-config.target", target);
cfg.setProperty("edit-config.default-operation", netconfOperation);
cfg.setProperty("edit-config.config.capable-switch.id", parseCapableSwitchId(actualCfg));
cfg.setProperty("edit-config.config.capable-switch." + "logical-switches.switch.id", parseSwitchId(actualCfg));
List<ConfigurationNode> newControllers = new ArrayList<>();
for (ControllerInfo ci : controllers) {
XMLConfiguration controller = new XMLConfiguration();
controller.setRoot(new HierarchicalConfiguration.Node("controller"));
String id = ci.type() + ":" + ci.ip() + ":" + ci.port();
controller.setProperty("id", id);
controller.setProperty("ip-address", ci.ip());
controller.setProperty("port", ci.port());
controller.setProperty("protocol", ci.type());
newControllers.add(controller.getRootNode());
}
cfg.addNodes("edit-config.config.capable-switch.logical-switches." + "switch.controllers", newControllers);
XMLConfiguration editcfg = (XMLConfiguration) cfg;
StringWriter stringWriter = new StringWriter();
try {
editcfg.save(stringWriter);
} catch (ConfigurationException e) {
log.error("createControllersConfig()", e);
}
String s = stringWriter.toString().replaceAll("<controller>", "<controller nc:operation=\"" + controllerOperation + "\">");
s = s.replace("<target>" + target + "</target>", "<target><" + target + "/></target>");
return s;
}
use of org.onosproject.net.behaviour.ControllerInfo in project onos by opennetworkinglab.
the class ServerControllerConfigTest method testGetControllers.
/**
* Test of getControllers().
*/
@Test
public void testGetControllers() {
// Get device handler
DriverHandler driverHandler = null;
try {
driverHandler = driverService.createHandler(restDeviceId1);
} catch (Exception e) {
throw e;
}
assertThat(driverHandler, notNullValue());
// Ask for the controllers of this device
List<ControllerInfo> receivedControllers = null;
// TODO: Fix this test
}
use of org.onosproject.net.behaviour.ControllerInfo in project onos by opennetworkinglab.
the class ControllerConfigJuniperImpl method getControllers.
@Override
public List<ControllerInfo> getControllers() {
List<ControllerInfo> controllers = Lists.newArrayList();
String reply = retrieveResultCommand(buildRpcGetOpenFlowController());
if (reply == null || reply.isEmpty()) {
log.error("Cannot get the controllers from switch");
} else {
controllers = getOpenFlowControllersFromConfig(XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes())));
log.debug("controllers {}", controllers);
}
return controllers;
}
use of org.onosproject.net.behaviour.ControllerInfo in project onos by opennetworkinglab.
the class ControllerConfigJuniperImpl method buildRpcSetOpenFlowController.
private static String buildRpcSetOpenFlowController(List<ControllerInfo> controllers) {
StringBuilder request = new StringBuilder();
request.append("<protocols>");
request.append("<openflow operation=\"delete\"/>");
request.append("</protocols>");
request.append("<protocols>");
request.append("<openflow>");
request.append("<mode>");
request.append("<ofagent-mode>");
request.append("<controller>");
for (ControllerInfo controller : controllers) {
request.append("<ip>");
request.append("<name>");
request.append(controller.ip().toString());
request.append("</name>");
request.append("<protocol>");
request.append("<tcp>");
request.append("<port>");
request.append(controller.port());
request.append("</port>");
request.append("</tcp>");
request.append("</protocol>");
request.append("</ip>");
}
request.append("</controller>");
request.append("</ofagent-mode>");
request.append("</mode>");
request.append("</openflow>");
request.append("</protocols>");
return cliSetRequestBuilder(request);
}
Aggregations