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));
}
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);
}
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"));
}
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));
}
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);
}
Aggregations