Search in sources :

Example 16 with ControllerInfo

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)));
}
Also used : XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) ArrayList(java.util.ArrayList) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo) Test(org.junit.Test)

Example 17 with ControllerInfo

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;
}
Also used : XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) StringWriter(java.io.StringWriter) ConfigurationNode(org.apache.commons.configuration.tree.ConfigurationNode) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) ArrayList(java.util.ArrayList) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo)

Example 18 with ControllerInfo

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
}
Also used : DriverHandler(org.onosproject.net.driver.DriverHandler) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo) Test(org.junit.Test)

Example 19 with ControllerInfo

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;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo)

Example 20 with ControllerInfo

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);
}
Also used : ControllerInfo(org.onosproject.net.behaviour.ControllerInfo)

Aggregations

ControllerInfo (org.onosproject.net.behaviour.ControllerInfo)38 ArrayList (java.util.ArrayList)19 DeviceId (org.onosproject.net.DeviceId)11 IpAddress (org.onlab.packet.IpAddress)9 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 Test (org.junit.Test)7 Device (org.onosproject.net.Device)6 BridgeConfig (org.onosproject.net.behaviour.BridgeConfig)6 BridgeDescription (org.onosproject.net.behaviour.BridgeDescription)6 DefaultBridgeDescription (org.onosproject.net.behaviour.DefaultBridgeDescription)6 OvsdbClientService (org.onosproject.ovsdb.controller.OvsdbClientService)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 List (java.util.List)5 Objects (java.util.Objects)5 Collectors (java.util.stream.Collectors)5 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)5 DriverHandler (org.onosproject.net.driver.DriverHandler)5 Logger (org.slf4j.Logger)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4