Search in sources :

Example 6 with ConfigApplyDelegate

use of org.onosproject.net.config.ConfigApplyDelegate in project onos by opennetworkinglab.

the class BasicLinkConfigTest method testConstruction.

/**
 * Tests construction, setters and getters of a BasicLinkConfig object.
 */
@Test
public void testConstruction() {
    BasicLinkConfig config = new BasicLinkConfig();
    ConfigApplyDelegate delegate = configApply -> {
    };
    ObjectMapper mapper = new ObjectMapper();
    LinkKey linkKey = LinkKey.linkKey(NetTestTools.connectPoint("device1", 1), NetTestTools.connectPoint("device2", 2));
    config.init(linkKey, "KEY", JsonNodeFactory.instance.objectNode(), mapper, delegate);
    config.bandwidth(BANDWIDTH).jitter(JITTER).delay(DELAY).loss(LOSS).availability(AVAILABILITY).flapping(FLAPPING).isDurable(FALSE).metric(METRIC).type(Link.Type.DIRECT).latency(LATENCY).isBidirectional(FALSE).isMetered(TRUE).tier(TIER).meteredUsage(METERED_USAGE);
    assertThat(config.bandwidth(), is(BANDWIDTH));
    assertThat(config.jitter(), is(JITTER));
    assertThat(config.delay(), is(DELAY));
    assertThat(config.loss(), is(LOSS));
    assertThat(config.availability(), is(AVAILABILITY));
    assertThat(config.flapping(), is(FLAPPING));
    assertThat(config.isDurable(), is(FALSE));
    assertThat(config.metric(), is(METRIC));
    assertThat(config.type(), is(Link.Type.DIRECT));
    assertThat(config.latency(), is(LATENCY));
    assertThat(config.isBidirectional(), is(FALSE));
    assertThat(config.isValid(), is(true));
    assertThat(config.isMetered(), is(TRUE));
    assertThat(config.tier(), is(TIER));
    assertThat(config.meteredUsage(), is(METERED_USAGE));
}
Also used : FALSE(java.lang.Boolean.FALSE) NetTestTools(org.onosproject.net.NetTestTools) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) ConfigApplyDelegate(org.onosproject.net.config.ConfigApplyDelegate) Duration(java.time.Duration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Link(org.onosproject.net.Link) TRUE(java.lang.Boolean.TRUE) LinkKey(org.onosproject.net.LinkKey) LinkKey(org.onosproject.net.LinkKey) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ConfigApplyDelegate(org.onosproject.net.config.ConfigApplyDelegate) Test(org.junit.Test)

Example 7 with ConfigApplyDelegate

use of org.onosproject.net.config.ConfigApplyDelegate in project onos by opennetworkinglab.

the class HostLearningConfigTest method setUp.

/**
 * Initialize test related variables.
 *
 * @throws Exception
 */
@Before
public void setUp() throws Exception {
    InputStream jsonStream = HostLearningConfigTest.class.getResourceAsStream("/host-learning-config.json");
    InputStream invalidJsonStream = HostLearningConfigTest.class.getResourceAsStream("/host-learning-config-invalid.json");
    cp = new ConnectPoint(DeviceId.deviceId(new URI("of:0000000000000202")), PortNumber.portNumber((long) 5));
    ConnectPoint subject = cp;
    String key = CoreService.CORE_APP_NAME;
    ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonNode = mapper.readTree(jsonStream);
    JsonNode invalidJsonNode = mapper.readTree(invalidJsonStream);
    ConfigApplyDelegate delegate = new MockDelegate();
    config = new HostLearningConfig();
    config.init(subject, key, jsonNode, mapper, delegate);
    invalidConfig = new HostLearningConfig();
    invalidConfig.init(subject, key, invalidJsonNode, mapper, delegate);
}
Also used : InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode) ConnectPoint(org.onosproject.net.ConnectPoint) URI(java.net.URI) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ConfigApplyDelegate(org.onosproject.net.config.ConfigApplyDelegate) Before(org.junit.Before)

Example 8 with ConfigApplyDelegate

use of org.onosproject.net.config.ConfigApplyDelegate in project onos by opennetworkinglab.

the class BandwidthCapacityTest method testConstruction.

@Test
public void testConstruction() {
    BandwidthCapacity config = new BandwidthCapacity();
    ConfigApplyDelegate delegate = configApply -> {
    };
    ObjectMapper mapper = new ObjectMapper();
    ConnectPoint cp = NetTestTools.connectPoint("cp1", 3);
    config.init(cp, "KEY", JsonNodeFactory.instance.objectNode(), mapper, delegate);
    double expectedBw = 1.0;
    config.capacity(Bandwidth.mbps(expectedBw));
    assertThat(config.isValid(), is(true));
    assertThat(config.toString(), containsString("capacity"));
}
Also used : NetTestTools(org.onosproject.net.NetTestTools) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) Bandwidth(org.onlab.util.Bandwidth) ConfigApplyDelegate(org.onosproject.net.config.ConfigApplyDelegate) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Matchers.containsString(org.hamcrest.Matchers.containsString) ConnectPoint(org.onosproject.net.ConnectPoint) ConnectPoint(org.onosproject.net.ConnectPoint) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ConfigApplyDelegate(org.onosproject.net.config.ConfigApplyDelegate) Test(org.junit.Test)

Example 9 with ConfigApplyDelegate

use of org.onosproject.net.config.ConfigApplyDelegate in project onos by opennetworkinglab.

the class VplsConfigManagerTest method testReloadConfigUpdateVpls.

/**
 * Updates VPLSs by sending new VPLS config.
 */
@Test
public void testReloadConfigUpdateVpls() {
    ((TestVpls) vplsConfigManager.vpls).initSampleData();
    VplsAppConfig vplsAppConfig = new VplsAppConfig();
    final ObjectMapper mapper = new ObjectMapper();
    final ConfigApplyDelegate delegate = new VplsAppConfigTest.MockCfgDelegate();
    JsonNode tree = null;
    try {
        tree = new ObjectMapper().readTree(TestConfigService.EMPTY_JSON_TREE);
    } catch (IOException e) {
        e.printStackTrace();
    }
    vplsAppConfig.init(APPID, APP_NAME, tree, mapper, delegate);
    VplsConfig vplsConfig = new VplsConfig(VPLS1, ImmutableSet.of(V100H1.name()), EncapsulationType.MPLS);
    vplsAppConfig.addVpls(vplsConfig);
    ((TestConfigService) vplsConfigManager.configService).setConfig(vplsAppConfig);
    NetworkConfigEvent event = new NetworkConfigEvent(NetworkConfigEvent.Type.CONFIG_ADDED, null, VplsAppConfig.class);
    ((TestConfigService) vplsConfigManager.configService).sendEvent(event);
    Collection<VplsData> vplss = vplsConfigManager.vpls.getAllVpls();
    assertEquals(1, vplss.size());
    VplsData expect = VplsData.of(VPLS1, EncapsulationType.MPLS);
    expect.addInterfaces(ImmutableSet.of(V100H1));
    expect.state(VplsData.VplsState.ADDED);
    assertTrue(vplss.contains(expect));
}
Also used : NetworkConfigEvent(org.onosproject.net.config.NetworkConfigEvent) VplsData(org.onosproject.vpls.api.VplsData) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ConfigApplyDelegate(org.onosproject.net.config.ConfigApplyDelegate) VplsTest(org.onosproject.vpls.VplsTest) Test(org.junit.Test)

Example 10 with ConfigApplyDelegate

use of org.onosproject.net.config.ConfigApplyDelegate in project onos by opennetworkinglab.

the class NetconfControllerImplTest method setUp.

@Before
public void setUp() throws Exception {
    ctrl = new NetconfControllerImpl();
    ctrl.deviceFactory = (ncDevInfo) -> new TestNetconfDevice(ncDevInfo);
    ctrl.cfgService = cfgService;
    ctrl.deviceService = deviceService;
    ctrl.deviceKeyService = deviceKeyService;
    ctrl.netCfgService = netCfgService;
    ctrl.mastershipService = mastershipService;
    NetconfControllerImpl.netconfConnectTimeout = NETCONF_CONNECT_TIMEOUT_DEFAULT;
    NetconfControllerImpl.netconfIdleTimeout = NETCONF_IDLE_TIMEOUT_DEFAULT;
    NetconfControllerImpl.netconfReplyTimeout = NETCONF_REPLY_TIMEOUT_DEFAULT;
    ctrl.clusterCommunicator = clusterCommunicationService;
    ctrl.clusterService = mockClusterService;
    // Creating mock devices
    deviceInfo1 = new NetconfDeviceInfo("device1", "001", IpAddress.valueOf(DEVICE_1_IP), DEVICE_1_PORT);
    deviceInfo2 = new NetconfDeviceInfo("device2", "002", IpAddress.valueOf(DEVICE_2_IP), DEVICE_2_PORT);
    deviceInfo2.setSshClientLib(Optional.of(NetconfSshClientLib.APACHE_MINA));
    badDeviceInfo3 = new NetconfDeviceInfo("device3", "003", IpAddress.valueOf(BAD_DEVICE_IP), BAD_DEVICE_PORT);
    deviceInfoIpV6 = new NetconfDeviceInfo("deviceIpv6", "004", IpAddress.valueOf(DEVICE_IPV6), IPV6_DEVICE_PORT);
    deviceConfig10Id = DeviceId.deviceId("netconf:" + DEVICE_10_IP + ":" + DEVICE_10_PORT);
    // Create a JSON entry just like Network Config accepts
    ObjectMapper mapper = new ObjectMapper();
    String jsonMessage = "{\n" + "  \"ip\":\"" + DEVICE_10_IP + "\",\n" + "  \"port\":" + DEVICE_10_PORT + ",\n" + "  \"username\":\"" + DEVICE_10_USERNAME + "\",\n" + "  \"password\":\"" + DEVICE_10_PASSWORD + "\",\n" + "  \"" + NetconfDeviceConfig.CONNECT_TIMEOUT + "\":" + DEVICE_10_CONNECT_TIMEOUT + ",\n" + "  \"" + NetconfDeviceConfig.REPLY_TIMEOUT + "\":" + DEVICE_10_REPLY_TIMEOUT + ",\n" + "  \"" + NetconfDeviceConfig.IDLE_TIMEOUT + "\":" + DEVICE_10_IDLE_TIMEOUT + ",\n" + "  \"" + NetconfDeviceConfig.SSHCLIENT + "\":\"" + NetconfSshClientLib.APACHE_MINA.toString() + "\"\n" + "}";
    InputStream jsonStream = new ByteArrayInputStream(jsonMessage.getBytes());
    JsonNode jsonNode = mapper.readTree(jsonStream);
    jsonStream.close();
    ConfigApplyDelegate delegate = new MockDelegate();
    deviceConfig10 = new NetconfDeviceConfig();
    deviceConfig10.init(deviceConfig10Id, "netconf", jsonNode, mapper, delegate);
    device1 = new TestNetconfDevice(deviceInfo1);
    deviceId1 = deviceInfo1.getDeviceId();
    device2 = new TestNetconfDevice(deviceInfo2);
    deviceId2 = deviceInfo2.getDeviceId();
    // Adding to the map for testing get device calls.
    Field field1 = ctrl.getClass().getDeclaredField("netconfDeviceMap");
    field1.setAccessible(true);
    reflectedDeviceMap = (Map<DeviceId, NetconfDevice>) field1.get(ctrl);
    reflectedDeviceMap.put(deviceId1, device1);
    reflectedDeviceMap.put(deviceId2, device2);
    // Creating mock events for testing NetconfDeviceOutputEventListener
    Field field2 = ctrl.getClass().getDeclaredField("downListener");
    field2.setAccessible(true);
    reflectedDownListener = (NetconfDeviceOutputEventListener) field2.get(ctrl);
    eventForDeviceInfo1 = new NetconfDeviceOutputEvent(NetconfDeviceOutputEvent.Type.DEVICE_NOTIFICATION, null, null, Optional.of(1), deviceInfo1);
    eventForDeviceInfo2 = new NetconfDeviceOutputEvent(NetconfDeviceOutputEvent.Type.DEVICE_UNREGISTERED, null, null, Optional.of(2), deviceInfo2);
}
Also used : NetconfDeviceInfo(org.onosproject.netconf.NetconfDeviceInfo) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DeviceId(org.onosproject.net.DeviceId) JsonNode(com.fasterxml.jackson.databind.JsonNode) ConfigApplyDelegate(org.onosproject.net.config.ConfigApplyDelegate) NetconfDeviceOutputEvent(org.onosproject.netconf.NetconfDeviceOutputEvent) Field(java.lang.reflect.Field) NetconfDevice(org.onosproject.netconf.NetconfDevice) ByteArrayInputStream(java.io.ByteArrayInputStream) NetconfDeviceConfig(org.onosproject.netconf.config.NetconfDeviceConfig) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Aggregations

ConfigApplyDelegate (org.onosproject.net.config.ConfigApplyDelegate)22 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)19 JsonNode (com.fasterxml.jackson.databind.JsonNode)16 Before (org.junit.Before)16 Test (org.junit.Test)10 InputStream (java.io.InputStream)7 DeviceId (org.onosproject.net.DeviceId)7 JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)6 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)5 Matchers.is (org.hamcrest.Matchers.is)5 TestApplicationId (org.onosproject.TestApplicationId)5 Set (java.util.Set)4 Assert (org.junit.Assert)4 ApplicationId (org.onosproject.core.ApplicationId)4 ConnectPoint (org.onosproject.net.ConnectPoint)4 Map (java.util.Map)3 IpAddress (org.onlab.packet.IpAddress)3 VlanId (org.onlab.packet.VlanId)3 HostId (org.onosproject.net.HostId)3 HostLocation (org.onosproject.net.HostLocation)3