Andrea Campanella
Committed by Gerrit Code Review

[ONOS-4045]Adding mastership service to NetconfProvider

Change-Id: Id39cbef54a079ab6e080a9d3f60770c4bea90b3f
......@@ -18,6 +18,7 @@ package org.onosproject.drivers.netconf;
import com.google.common.base.Preconditions;
import org.onosproject.drivers.utilities.XmlConfigParser;
import org.onosproject.mastership.MastershipService;
import org.onosproject.net.DeviceId;
import org.onosproject.net.behaviour.ControllerConfig;
import org.onosproject.net.behaviour.ControllerInfo;
......@@ -44,21 +45,29 @@ public class NetconfControllerConfig extends AbstractHandlerBehaviour
private final Logger log = getLogger(NetconfControllerConfig.class);
@Override
public List<ControllerInfo> getControllers() {
DriverHandler handler = handler();
NetconfController controller = handler.get(NetconfController.class);
DeviceId ofDeviceId = handler.data().deviceId();
MastershipService mastershipService = handler.get(MastershipService.class);
DeviceId deviceId = handler.data().deviceId();
Preconditions.checkNotNull(controller, "Netconf controller is null");
List<ControllerInfo> controllers = new ArrayList<>();
try {
String reply = controller.getDevicesMap().get(ofDeviceId).getSession().
getConfig("running");
log.debug("Reply XML {}", reply);
controllers.addAll(XmlConfigParser.parseStreamControllers(XmlConfigParser.
loadXml(new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8)))));
} catch (IOException e) {
log.error("Cannot communicate with device {} ", ofDeviceId);
if (mastershipService.isLocalMaster(deviceId)) {
try {
String reply = controller.getNetconfDevice(deviceId).getSession().
getConfig("running");
log.debug("Reply XML {}", reply);
controllers.addAll(XmlConfigParser.parseStreamControllers(XmlConfigParser.
loadXml(new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8)))));
} catch (IOException 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;
}
......@@ -69,30 +78,36 @@ public class NetconfControllerConfig extends AbstractHandlerBehaviour
NetconfController controller = handler.get(NetconfController.class);
DeviceId deviceId = handler.data().deviceId();
Preconditions.checkNotNull(controller, "Netconf controller is null");
try {
NetconfDevice device = controller.getNetconfDevice(deviceId);
String config = null;
MastershipService mastershipService = handler.get(MastershipService.class);
if (mastershipService.isLocalMaster(deviceId)) {
try {
String reply = device.getSession().getConfig("running");
log.info("reply XML {}", reply);
config = XmlConfigParser.createControllersConfig(
XmlConfigParser.loadXml(getClass().getResourceAsStream("controllers.xml")),
XmlConfigParser.loadXml(
new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8))),
"running", "merge", "create", controllers
);
NetconfDevice device = controller.getNetconfDevice(deviceId);
String config = null;
try {
String reply = device.getSession().getConfig("running");
log.info("reply XML {}", reply);
config = XmlConfigParser.createControllersConfig(
XmlConfigParser.loadXml(getClass().getResourceAsStream("controllers.xml")),
XmlConfigParser.loadXml(
new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8))),
"running", "merge", "create", controllers
);
} catch (IOException e) {
log.error("Cannot comunicate to device {} , exception {}", deviceId, e.getMessage());
}
device.getSession().editConfig(config.substring(config.indexOf("-->") + 3));
} catch (NullPointerException e) {
log.warn("No NETCONF device with requested parameters " + e);
throw new NullPointerException("No NETCONF device with requested parameters " + e);
} catch (IOException e) {
log.error("Cannot comunicate to device {} , exception {}", deviceId, e.getMessage());
}
device.getSession().editConfig(config.substring(config.indexOf("-->") + 3));
} catch (NullPointerException e) {
log.warn("No NETCONF device with requested parameters " + e);
throw new NullPointerException("No NETCONF device with requested parameters " + e);
} catch (IOException e) {
log.error("Cannot comunicate to device {} , exception {}", deviceId, e.getMessage());
} else {
log.warn("I'm not master for {} please use master, {} to execute command",
deviceId,
mastershipService.getMasterFor(deviceId));
}
}
//TODO maybe put method getNetconfClientService like in ovsdb if we need it
......
......@@ -46,31 +46,31 @@ public interface NetconfController {
* Tries to connect to a specific NETCONF device, if the connection is succesful
* it creates and adds the device to the ONOS core as a NetconfDevice.
*
* @param deviceInfo info about the device to add
* @param deviceId deviceId of the device to connect
* @return NetconfDevice Netconf device
* @throws NetconfException when device is not available
*/
NetconfDevice connectDevice(NetconfDeviceInfo deviceInfo) throws NetconfException;
NetconfDevice connectDevice(DeviceId deviceId) throws NetconfException;
/**
* Disconnects a Netconf device and removes it from the core.
*
* @param deviceInfo info about the device to remove
* @param deviceId id of the device to remove
* @param remove true if device is to be removed from core
*/
void disconnectDevice(NetconfDeviceInfo deviceInfo);
void disconnectDevice(DeviceId deviceId, boolean remove);
/**
* Removes a Netconf device from the core.
*
* @param deviceInfo info about the device to remove
* @param deviceId id of the device to remove
*/
void removeDevice(NetconfDeviceInfo deviceInfo);
void removeDevice(DeviceId deviceId);
/**
* Gets all the nodes information.
*
* @return map of devices
*
*/
Map<DeviceId, NetconfDevice> getDevicesMap();
......@@ -97,5 +97,4 @@ public interface NetconfController {
* @return NetconfDevice Netconf device
*/
NetconfDevice getNetconfDevice(IpAddress ip, int port);
}
......
......@@ -16,22 +16,25 @@
package org.onosproject.netconf;
import org.onosproject.net.DeviceId;
/**
* Allows for providers interested in node events to be notified.
*/
public interface NetconfDeviceListener {
/**
* Notifies that the node was added.
* Notifies that the device was added.
*
* @param nodeId the node where the event occurred
* @param deviceId the device that was added
*/
void deviceAdded(NetconfDeviceInfo nodeId);
void deviceAdded(DeviceId deviceId);
/**
* Notifies that the node was removed.
* Notifies that the device was removed.
*
* @param nodeId the node where the event occurred
* @param deviceId the device that was removed
*/
void deviceRemoved(NetconfDeviceInfo nodeId);
void deviceRemoved(DeviceId deviceId);
}
......
......@@ -35,7 +35,7 @@ public class DefaultNetconfDevice implements NetconfDevice {
.getLogger(DefaultNetconfDevice.class);
private NetconfDeviceInfo netconfDeviceInfo;
private boolean deviceState = false;
private boolean deviceState = true;
protected NetconfSessionFactory sessionFactory = new SshNetconfSessionFactory();
private NetconfSession netconfSession;
......@@ -53,10 +53,10 @@ public class DefaultNetconfDevice implements NetconfDevice {
try {
netconfSession = sessionFactory.createNetconfSession(deviceInfo);
} catch (IOException e) {
deviceState = false;
throw new NetconfException("Cannot create connection and session for device " +
deviceInfo, e);
}
deviceState = true;
}
@Override
......
......@@ -19,9 +19,16 @@ package org.onosproject.netconf.ctl;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onlab.packet.IpAddress;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.device.DeviceService;
import org.onosproject.net.key.DeviceKeyId;
import org.onosproject.net.key.DeviceKeyService;
import org.onosproject.net.key.UsernamePassword;
import org.onosproject.netconf.NetconfController;
import org.onosproject.netconf.NetconfDevice;
import org.onosproject.netconf.NetconfDeviceFactory;
......@@ -34,6 +41,7 @@ import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Arrays;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
......@@ -45,6 +53,11 @@ import java.util.concurrent.CopyOnWriteArraySet;
@Component(immediate = true)
@Service
public class NetconfControllerImpl implements NetconfController {
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DeviceService deviceService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DeviceKeyService deviceKeyService;
public static final Logger log = LoggerFactory
.getLogger(NetconfControllerImpl.class);
......@@ -95,55 +108,93 @@ public class NetconfControllerImpl implements NetconfController {
}
@Override
public NetconfDevice connectDevice(NetconfDeviceInfo deviceInfo) throws NetconfException {
if (netconfDeviceMap.containsKey(deviceInfo.getDeviceId())) {
log.info("Device {} is already present", deviceInfo);
return netconfDeviceMap.get(deviceInfo.getDeviceId());
public NetconfDevice connectDevice(DeviceId deviceId) throws NetconfException {
if (netconfDeviceMap.containsKey(deviceId)) {
log.debug("Device {} is already present", deviceId);
return netconfDeviceMap.get(deviceId);
} else {
log.info("Creating NETCONF device {}", deviceInfo);
NetconfDevice device = createDevice(deviceInfo);
device.getSession().addDeviceOutputListener(downListener);
return device;
log.debug("Creating NETCONF device {}", deviceId);
Device device = deviceService.getDevice(deviceId);
String ip;
int port;
if (device != null) {
ip = device.annotations().value("ipaddress");
port = Integer.parseInt(device.annotations().value("port"));
} else {
String[] info = deviceId.toString().split(":");
if (info.length == 3) {
ip = info[1];
port = Integer.parseInt(info[2]);
} else {
ip = Arrays.asList(info).stream().filter(el -> !el.equals(info[0])
&& !el.equals(info[info.length - 1]))
.reduce((t, u) -> t + ":" + u)
.get();
log.debug("ip v6 {}", ip);
port = Integer.parseInt(info[info.length - 1]);
}
}
try {
UsernamePassword deviceKey = deviceKeyService.getDeviceKey(
DeviceKeyId.deviceKeyId(deviceId.toString())).asUsernamePassword();
NetconfDeviceInfo deviceInfo = new NetconfDeviceInfo(deviceKey.username(),
deviceKey.password(),
IpAddress.valueOf(ip),
port);
NetconfDevice netconfDevicedevice = createDevice(deviceInfo);
netconfDevicedevice.getSession().addDeviceOutputListener(downListener);
return netconfDevicedevice;
} catch (NullPointerException e) {
throw new NetconfException("No Device Key for device " + deviceId, e);
}
}
}
@Override
public void disconnectDevice(NetconfDeviceInfo deviceInfo) {
if (!netconfDeviceMap.containsKey(deviceInfo.getDeviceId())) {
log.warn("Device {} is not present", deviceInfo);
public void disconnectDevice(DeviceId deviceId, boolean remove) {
if (!netconfDeviceMap.containsKey(deviceId)) {
log.warn("Device {} is not present", deviceId);
} else {
stopDevice(deviceInfo);
stopDevice(deviceId, remove);
}
}
private void stopDevice(DeviceId deviceId, boolean remove) {
netconfDeviceMap.get(deviceId).disconnect();
netconfDeviceMap.remove(deviceId);
if (remove) {
for (NetconfDeviceListener l : netconfDeviceListeners) {
l.deviceRemoved(deviceId);
}
}
}
@Override
public void removeDevice(NetconfDeviceInfo deviceInfo) {
if (!netconfDeviceMap.containsKey(deviceInfo.getDeviceId())) {
log.warn("Device {} is not present", deviceInfo);
public void removeDevice(DeviceId deviceId) {
if (!netconfDeviceMap.containsKey(deviceId)) {
log.warn("Device {} is not present", deviceId);
for (NetconfDeviceListener l : netconfDeviceListeners) {
l.deviceRemoved(deviceId);
}
} else {
netconfDeviceMap.remove(deviceInfo.getDeviceId());
netconfDeviceMap.remove(deviceId);
for (NetconfDeviceListener l : netconfDeviceListeners) {
l.deviceRemoved(deviceInfo);
l.deviceRemoved(deviceId);
}
}
}
private NetconfDevice createDevice(NetconfDeviceInfo deviceInfo) throws NetconfException {
NetconfDevice netconfDevice = deviceFactory.createNetconfDevice(deviceInfo);
netconfDeviceMap.put(deviceInfo.getDeviceId(), netconfDevice);
for (NetconfDeviceListener l : netconfDeviceListeners) {
l.deviceAdded(deviceInfo);
l.deviceAdded(deviceInfo.getDeviceId());
}
netconfDeviceMap.put(deviceInfo.getDeviceId(), netconfDevice);
return netconfDevice;
}
private void stopDevice(NetconfDeviceInfo deviceInfo) {
netconfDeviceMap.get(deviceInfo.getDeviceId()).disconnect();
netconfDeviceMap.remove(deviceInfo.getDeviceId());
for (NetconfDeviceListener l : netconfDeviceListeners) {
l.deviceRemoved(deviceInfo);
}
}
@Override
public Map<DeviceId, NetconfDevice> getDevicesMap() {
......@@ -155,6 +206,8 @@ public class NetconfControllerImpl implements NetconfController {
return netconfDeviceMap.keySet();
}
//Device factory for the specific NetconfDeviceImpl
private class DefaultNetconfDeviceFactory implements NetconfDeviceFactory {
......@@ -171,7 +224,7 @@ public class NetconfControllerImpl implements NetconfController {
@Override
public void event(NetconfDeviceOutputEvent event) {
if (event.type().equals(NetconfDeviceOutputEvent.Type.DEVICE_UNREGISTERED)) {
removeDevice(event.getDeviceInfo());
removeDevice(event.getDeviceInfo().getDeviceId());
}
}
......
......@@ -375,13 +375,12 @@ public class NetconfSessionImpl implements NetconfSession {
private boolean close(boolean force) throws NetconfException {
StringBuilder rpc = new StringBuilder();
rpc.append("<rpc>");
rpc.append("<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">");
if (force) {
rpc.append("<kill-configuration/>");
rpc.append("<kill-session/>");
} else {
rpc.append("<close-configuration/>");
rpc.append("<close-session/>");
}
rpc.append("<close-configuration/>");
rpc.append("</rpc>");
rpc.append(ENDPATTERN);
return checkReply(sendRequest(rpc.toString())) || close(true);
......
......@@ -22,6 +22,8 @@ import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.IpAddress;
import org.onosproject.net.DeviceId;
import org.onosproject.net.device.DeviceService;
import org.onosproject.net.key.DeviceKeyService;
import org.onosproject.netconf.NetconfDevice;
import org.onosproject.netconf.NetconfDeviceFactory;
import org.onosproject.netconf.NetconfDeviceInfo;
......@@ -44,12 +46,14 @@ import static org.junit.Assert.*;
* Unit tests for the Netconf controller implementation test.
*/
public class NetconfControllerImplTest {
NetconfControllerImpl ctrl;
//DeviceInfo
NetconfDeviceInfo deviceInfo1;
NetconfDeviceInfo deviceInfo2;
NetconfDeviceInfo badDeviceInfo3;
NetconfDeviceInfo deviceInfoIpV6;
//Devices & DeviceId
NetconfDevice device1;
......@@ -68,21 +72,29 @@ public class NetconfControllerImplTest {
private static final String DEVICE_1_IP = "10.10.10.11";
private static final String DEVICE_2_IP = "10.10.10.12";
private static final String BAD_DEVICE_IP = "10.10.10.13";
private static final String DEVICE_IPV6 = "2001:db8::1";
private static final int DEVICE_1_PORT = 11;
private static final int DEVICE_2_PORT = 12;
private static final int BAD_DEVICE_PORT = 13;
private static final int IPV6_DEVICE_PORT = 14;
private static DeviceService deviceService = new NetconfDeviceServiceMock();
private static DeviceKeyService deviceKeyService = new NetconfDeviceKeyServiceMock();
@Before
public void setUp() throws Exception {
ctrl = new NetconfControllerImpl();
ctrl.deviceFactory = new TestNetconfDeviceFactory();
ctrl.deviceService = deviceService;
ctrl.deviceKeyService = deviceKeyService;
//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);
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);
device1 = new TestNetconfDevice(deviceInfo1);
deviceId1 = deviceInfo1.getDeviceId();
......@@ -102,9 +114,9 @@ public class NetconfControllerImplTest {
reflectedDownListener = (NetconfDeviceOutputEventListener) field2.get(ctrl);
eventForDeviceInfo1 = new NetconfDeviceOutputEvent(NetconfDeviceOutputEvent.Type.DEVICE_NOTIFICATION, null,
null, Optional.of(1), deviceInfo1);
null, Optional.of(1), deviceInfo1);
eventForDeviceInfo2 = new NetconfDeviceOutputEvent(NetconfDeviceOutputEvent.Type.DEVICE_UNREGISTERED, null,
null, Optional.of(2), deviceInfo2);
null, Optional.of(2), deviceInfo2);
}
@After
......@@ -128,7 +140,7 @@ public class NetconfControllerImplTest {
ctrl.addDeviceListener(deviceListener3);
assertThat("Incorrect number of listeners", ctrl.netconfDeviceListeners, hasSize(3));
assertThat("Not matching listeners", ctrl.netconfDeviceListeners, hasItems(deviceListener1,
deviceListener2, deviceListener3));
deviceListener2, deviceListener3));
ctrl.removeDeviceListener(deviceListener1);
assertThat("Incorrect number of listeners", ctrl.netconfDeviceListeners, hasSize(2));
......@@ -168,7 +180,7 @@ public class NetconfControllerImplTest {
public void testConnectBadDevice() throws Exception {
reflectedDeviceMap.clear();
try {
ctrl.connectDevice(badDeviceInfo3);
ctrl.connectDevice(badDeviceInfo3.getDeviceId());
} finally {
assertEquals("Incorrect device connection", 0, ctrl.getDevicesMap().size());
}
......@@ -180,25 +192,37 @@ public class NetconfControllerImplTest {
@Test
public void testConnectCorrectDevice() throws Exception {
reflectedDeviceMap.clear();
ctrl.connectDevice(deviceInfo1);
ctrl.connectDevice(deviceInfo2);
ctrl.connectDevice(deviceInfo1.getDeviceId());
ctrl.connectDevice(deviceInfo2.getDeviceId());
assertTrue("Incorrect device connection", ctrl.getDevicesMap().containsKey(deviceId1));
assertTrue("Incorrect device connection", ctrl.getDevicesMap().containsKey(deviceId2));
assertEquals("Incorrect device connection", 2, ctrl.getDevicesMap().size());
}
/**
* Check for correct ipv6 device connection. In this case the device map get modified.
*/
@Test
public void testConnectCorrectIpv6Device() throws Exception {
reflectedDeviceMap.clear();
ctrl.connectDevice(deviceInfoIpV6.getDeviceId());
assertTrue("Incorrect device connection", ctrl.getDevicesMap()
.containsKey(deviceInfoIpV6.getDeviceId()));
assertEquals("Incorrect device connection", 1, ctrl.getDevicesMap().size());
}
/**
* Check for connect devices already added to the map.
*/
@Test
public void testConnectAlreadyExistingDevice() throws Exception {
NetconfDevice alreadyExistingDevice1 = ctrl.connectDevice(deviceInfo1);
NetconfDevice alreadyExistingDevice2 = ctrl.connectDevice(deviceInfo2);
NetconfDevice alreadyExistingDevice1 = ctrl.connectDevice(deviceInfo1.getDeviceId());
NetconfDevice alreadyExistingDevice2 = ctrl.connectDevice(deviceInfo2.getDeviceId());
assertEquals("Incorrect device connection", alreadyExistingDevice1.getDeviceInfo().getDeviceId(),
deviceInfo1.getDeviceId());
deviceInfo1.getDeviceId());
assertEquals("Incorrect device connection", alreadyExistingDevice2.getDeviceInfo().getDeviceId(),
deviceInfo2.getDeviceId());
deviceInfo2.getDeviceId());
}
/**
......@@ -206,7 +230,7 @@ public class NetconfControllerImplTest {
*/
@Test
public void testDisconnectDevice() throws Exception {
ctrl.disconnectDevice(deviceInfo1);
ctrl.disconnectDevice(deviceInfo1.getDeviceId(), true);
assertFalse("Incorrect device removal", ctrl.getDevicesMap().containsKey(deviceId1));
}
......@@ -215,7 +239,7 @@ public class NetconfControllerImplTest {
*/
@Test
public void testRemoveDevice() throws Exception {
ctrl.removeDevice(deviceInfo1);
ctrl.removeDevice(deviceInfo1.getDeviceId());
assertFalse("Incorrect device removal", ctrl.getDevicesMap().containsKey(deviceId1));
}
......@@ -234,13 +258,13 @@ public class NetconfControllerImplTest {
@Test
public void testDeviceDownEventListener() throws Exception {
reflectedDeviceMap.clear();
ctrl.connectDevice(deviceInfo1);
ctrl.connectDevice(deviceInfo1.getDeviceId());
boolean result1 = reflectedDownListener.isRelevant(eventForDeviceInfo2);
assertFalse("Irrelevant Device Event", result1);
assertEquals("Incorrect device map size", 1, ctrl.getDevicesMap().size());
reflectedDownListener.event(eventForDeviceInfo1);
assertEquals("Incorrect device map size", 1, ctrl.getDevicesMap().size());
ctrl.connectDevice(deviceInfo2);
ctrl.connectDevice(deviceInfo2.getDeviceId());
boolean result2 = reflectedDownListener.isRelevant(eventForDeviceInfo2);
assertTrue("Irrelevant Device Event", result2);
assertEquals("Incorrect device map size", 2, ctrl.getDevicesMap().size());
......@@ -269,7 +293,7 @@ public class NetconfControllerImplTest {
public TestNetconfDevice(NetconfDeviceInfo deviceInfo) throws NetconfException {
netconfDeviceInfo = deviceInfo;
if (netconfDeviceInfo.ip() != badDeviceInfo3.ip()) {
if (!badDeviceInfo3.getDeviceId().equals(deviceInfo.getDeviceId())) {
netconfSession = EasyMock.createMock(NetconfSession.class);
deviceState = true;
} else {
......
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.netconf.ctl;
import org.onlab.packet.IpAddress;
import org.onosproject.net.key.DeviceKey;
import org.onosproject.net.key.DeviceKeyId;
import org.onosproject.net.key.DeviceKeyListener;
import org.onosproject.net.key.DeviceKeyService;
import org.onosproject.netconf.NetconfDeviceInfo;
import java.util.Collection;
/**
* Mock DeviceKey service to return device keys.
*/
class NetconfDeviceKeyServiceMock implements DeviceKeyService {
private static final String DEVICE_1_IP = "10.10.10.11";
private static final String DEVICE_2_IP = "10.10.10.12";
private static final String BAD_DEVICE_IP = "10.10.10.13";
private static final String DEVICE_IPV6 = "2001:db8::1";
private static final int DEVICE_1_PORT = 11;
private static final int DEVICE_2_PORT = 12;
private static final int BAD_DEVICE_PORT = 13;
private static final int IPV6_DEVICE_PORT = 14;
//DeviceInfo
private NetconfDeviceInfo deviceInfo1 =
new NetconfDeviceInfo("device1", "001", IpAddress.valueOf(DEVICE_1_IP),
DEVICE_1_PORT);
private NetconfDeviceInfo deviceInfo2 =
new NetconfDeviceInfo("device2", "002", IpAddress.valueOf(DEVICE_2_IP),
DEVICE_2_PORT);
private NetconfDeviceInfo badDeviceInfo3 =
new NetconfDeviceInfo("device3", "003", IpAddress.valueOf(BAD_DEVICE_IP),
BAD_DEVICE_PORT);
private NetconfDeviceInfo deviceInfoIpV6 =
new NetconfDeviceInfo("deviceIpv6", "004", IpAddress.valueOf(DEVICE_IPV6), IPV6_DEVICE_PORT);
@Override
public Collection<DeviceKey> getDeviceKeys() {
return null;
}
@Override
public DeviceKey getDeviceKey(DeviceKeyId deviceKeyId) {
if (deviceKeyId.toString().equals(deviceInfo1.getDeviceId().toString())) {
return DeviceKey.createDeviceKeyUsingUsernamePassword(
DeviceKeyId.deviceKeyId(deviceInfo1.getDeviceId().toString()),
null, deviceInfo1.name(), deviceInfo1.password());
} else if (deviceKeyId.toString().equals(deviceInfo2.getDeviceId().toString())) {
return DeviceKey.createDeviceKeyUsingUsernamePassword(
DeviceKeyId.deviceKeyId(deviceInfo2.getDeviceId().toString()),
null, deviceInfo2.name(), deviceInfo2.password());
} else if (deviceKeyId.toString().equals(badDeviceInfo3.getDeviceId().toString())) {
return DeviceKey.createDeviceKeyUsingUsernamePassword(
DeviceKeyId.deviceKeyId(badDeviceInfo3.getDeviceId().toString()),
null, badDeviceInfo3.name(), badDeviceInfo3.password());
} else if (deviceKeyId.toString().equals(deviceInfoIpV6.getDeviceId().toString())) {
return DeviceKey.createDeviceKeyUsingUsernamePassword(
DeviceKeyId.deviceKeyId(deviceInfoIpV6.getDeviceId().toString()),
null, deviceInfoIpV6.name(), deviceInfoIpV6.password());
}
return null;
}
@Override
public void addListener(DeviceKeyListener listener) {
}
@Override
public void removeListener(DeviceKeyListener listener) {
}
}
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.netconf.ctl;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.MastershipRole;
import org.onosproject.net.Port;
import org.onosproject.net.PortNumber;
import org.onosproject.net.device.DeviceListener;
import org.onosproject.net.device.DeviceService;
import org.onosproject.net.device.PortStatistics;
import java.util.List;
/**
* Mock device Service.
*/
class NetconfDeviceServiceMock implements DeviceService {
@Override
public int getDeviceCount() {
return 0;
}
@Override
public Iterable<Device> getDevices() {
return null;
}
@Override
public Iterable<Device> getDevices(Device.Type type) {
return null;
}
@Override
public Iterable<Device> getAvailableDevices() {
return null;
}
@Override
public Iterable<Device> getAvailableDevices(Device.Type type) {
return null;
}
@Override
public Device getDevice(DeviceId deviceId) {
return null;
}
@Override
public MastershipRole getRole(DeviceId deviceId) {
return null;
}
@Override
public List<Port> getPorts(DeviceId deviceId) {
return null;
}
@Override
public List<PortStatistics> getPortStatistics(DeviceId deviceId) {
return null;
}
@Override
public List<PortStatistics> getPortDeltaStatistics(DeviceId deviceId) {
return null;
}
@Override
public Port getPort(DeviceId deviceId, PortNumber portNumber) {
return null;
}
@Override
public boolean isAvailable(DeviceId deviceId) {
return false;
}
@Override
public void addListener(DeviceListener listener) {
}
@Override
public void removeListener(DeviceListener listener) {
}
}
\ No newline at end of file
......@@ -8,4 +8,4 @@ export OCN="10.128.12.4"
export OCT=$OC1
export ONOS_USE_SSH=true
export ONOS_APPS=drivers,openflow,proxyarp,ovsdb,pathpainter
export ONOS_APPS=drivers,openflow,proxyarp,ovsdb,pathpainter
\ No newline at end of file
......