Initial import of Microsemi Driver
Change-Id: I431d5f2c18e0b66a84c36273c3d9f0b84f223841
Added in BUCK files for building driver
Change-Id: I70681327f5b89f67e904c45d5974ab393652d51f
Corrected some syntax errors
Change-Id: I11150cc499c212005f80619e3900e747f1c23d96
Updated pom file to clean build
Change-Id: I6613ddc9e6802aa882e716cf04df210249870835
Added in utility functions for EA1000 Init
Change-Id: I51ffe0cf0daf9ffcea0e2479ee9982fcd1755440
Added YMS code to Microsemi Driver
Change-Id: I6f2a14e454c6909bf9e9f6025321c74c98c13c72
Updated driver to work with YMS and YCH
Change-Id: If7dbe3cd5bd1b6f902d09d6b2dc3895605d70f70
Implemented IetfSystemManager as a service and call on YMS as a service
Change-Id: If1c5e8482b1f53f578a3b0b770accd50024111cf
Moved YMS calls over in to Yang Service implementation
Change-Id: I044aad06f1ef7452bc48e88987787a683666cd72
improved unit test for IetfSystemManager
Change-Id: I48fbf831e7e5ca0e1ef3de8288e56da1b5ebb7a4
Major changes to IetfSystemManager to work in live system
Change-Id: I6e3aa118ba422151f314b9a666860d90905c9929
Added in retry mechanism for DeviceDescription to wait for YCH
Change-Id: If8e0f2c2f315ffd6db15627a11382a00217dd262
Added in implementation of MseaSaFiltering and unit tests
Change-Id: I34bf888e0e732bd4664d1fb8ef5abb679b1506fe
Updated driver with unit tests for MseaSaFiltering
Change-Id: I7ea2407a546622ff55d1ab21610c45697546d632
Modified removeFlowRules of Ea1000FlowRuleProgrammable
Change-Id: Ibb4a555f61887a8e6e42af588bb42f7b70f58efb
Added in manager for MseaUniEvc service with unit tests
Change-Id: Idc5853f46051548973f52a0659f7f88982ff960c
Implemented getFlowEntries() for EVCs from EA1000
Change-Id: Ie85dadfa7760f0b30a9bdf6ccd09cca9f097fff9
Added in translation of FlowRules in to EVC on EA1000
Change-Id: Icfb65171c3300c96b3ca4e18cbd327f0ed2190be
Added in handling of FlowRule deletion including complex ceVlanMaps
Change-Id: I7fd0bb0ef04d1b40e4b7d6a6db7f7ee662329780
Updated Service entries for new onos-yang-tools
Change-Id: I44e655202f3a45073e1e16f83737caed6e01afa8
Revert "Updated Service entries for new onos-yang-tools"
This reverts commit 642b550ef1de12ed59bad2eaa3a2da414d2e5e59.
Improved timeout mechanism for YANG model loading
Change-Id: If744ecd206372e822edf2b736c83226321a12256
Minor edits of EVC creation
Change-Id: Ib0a4763deaf6dce37625ba77f5095b39cd98272d
Added in CustomEvc and supporting classes
Change-Id: Iad60eb1bcd48d2aec55b894b2d419b51852c3b2f
Created CeVlanUtils to resolve loading problem
Change-Id: I0d63931ad2c5ad2725861ebc7dccc4d5fe7b9298
Modified startup check
Change-Id: I6e6bcfa7e615044cb08fe7ee2f8a6c8b89aabb21
Modified handlin of flow rules
Change-Id: I965a79c23298866122aeb94c6d9d584aafee3bd5
Fixed problem with ceVlanMap
Change-Id: If1458c35d0b95b5b25b6636f098292f9e91c06c6
Minor Pom edits
Change-Id: I5cefb18674aa04b1f50bd7e2306260c1c3ad3814
Commented out extension references in YANG files to avoid onos-yang-tools problems
Change-Id: I32fdb34c4f476f495fe28e75d0f410aaf14e2ec1
Corrected error in removing 0 in CeVlanMapUtils
Change-Id: I8cd1fd02788b81c2613364d5639ef6e090057f80
Changes in YMS to accomodate EA1000 driver
Change-Id: I6ae2b9bd2be49eae8d4ad2f929dfe3214c514550
diff --git a/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/MockCoreService.java b/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/MockCoreService.java
new file mode 100644
index 0000000..d63c5e6
--- /dev/null
+++ b/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/MockCoreService.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2017-present 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.drivers.netconf;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.onosproject.core.DefaultApplicationId;
+import org.onosproject.core.IdGenerator;
+import org.onosproject.core.Version;
+import org.onosproject.net.intent.MockIdGenerator;
+
+public class MockCoreService implements CoreService {
+
+ private HashSet<ApplicationId> appIds;
+ private Version version;
+ private IdGenerator idGenerator;
+
+ public MockCoreService() {
+ appIds = new HashSet<ApplicationId>();
+ appIds.add(new DefaultApplicationId(101, "org.onosproject.drivers.netconf"));
+ version = Version.version(1, 1, "1", "1");
+ idGenerator = new MockIdGenerator();
+ }
+
+ @Override
+ public Version version() {
+ return version;
+ }
+
+ @Override
+ public Set<ApplicationId> getAppIds() {
+ return appIds;
+ }
+
+ @Override
+ public ApplicationId getAppId(Short id) {
+ for (ApplicationId appId:appIds) {
+ if (appId.id() == id.shortValue()) {
+ return appId;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public ApplicationId getAppId(String name) {
+ for (ApplicationId appId:appIds) {
+ if (appId.name().equalsIgnoreCase(name)) {
+ return appId;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public ApplicationId registerApplication(String name) {
+ ApplicationId appId = new DefaultApplicationId(101, name);
+ appIds.add(appId);
+ return appId;
+ }
+
+ @Override
+ public ApplicationId registerApplication(String name, Runnable preDeactivate) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public IdGenerator getIdGenerator(String topic) {
+ return idGenerator;
+ }
+
+}
diff --git a/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/MockDriverHandler.java b/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/MockDriverHandler.java
new file mode 100644
index 0000000..b212496
--- /dev/null
+++ b/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/MockDriverHandler.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2017-present 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.drivers.netconf;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.onosproject.core.CoreService;
+import org.onosproject.mastership.MastershipService;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.driver.Behaviour;
+import org.onosproject.net.driver.DefaultDriver;
+import org.onosproject.net.driver.DefaultDriverData;
+import org.onosproject.net.driver.Driver;
+import org.onosproject.net.driver.DriverData;
+import org.onosproject.net.driver.DriverHandler;
+import org.onosproject.net.flow.FlowRuleProgrammable;
+import org.onosproject.netconf.NetconfController;
+import org.onosproject.netconf.NetconfException;
+
+public class MockDriverHandler implements DriverHandler {
+
+ private DriverData mockDriverData;
+
+ private NetconfController ncc;
+ private CoreService coreService;
+ private MastershipService mastershipService;
+
+ public MockDriverHandler() throws NetconfException {
+ Map<Class<? extends Behaviour>, Class<? extends Behaviour>> behaviours =
+ new HashMap<Class<? extends Behaviour>, Class<? extends Behaviour>>();
+ behaviours.put(FlowRuleProgrammable.class, FlowRuleProgrammable.class);
+
+ Map<String, String> properties = new HashMap<String, String>();
+
+ Driver mockDriver =
+ new DefaultDriver("mockDriver", null, "ONOSProject", "1.0.0", "1.0.0", behaviours, properties);
+ DeviceId mockDeviceId = DeviceId.deviceId("netconf:1.2.3.4:830");
+ mockDriverData = new DefaultDriverData(mockDriver, mockDeviceId);
+
+
+ ncc = new MockNetconfController();
+ ncc.connectDevice(mockDeviceId);
+
+ coreService = new MockCoreService();
+ mastershipService = new MockMastershipService();
+ }
+
+ @Override
+ public Driver driver() {
+ return mockDriverData.driver();
+ }
+
+ @Override
+ public DriverData data() {
+ return mockDriverData;
+ }
+
+ @Override
+ public <T extends Behaviour> T behaviour(Class<T> behaviourClass) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public <T> T get(Class<T> serviceClass) {
+ if (serviceClass.equals(NetconfController.class)) {
+ return (T) ncc;
+
+ } else if (serviceClass.equals(CoreService.class)) {
+ return (T) coreService;
+
+ } else if (serviceClass.equals(MastershipService.class)) {
+ return (T) mastershipService;
+
+ }
+
+ return null;
+ }
+
+}
diff --git a/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/MockMastershipService.java b/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/MockMastershipService.java
new file mode 100644
index 0000000..85cd5b1
--- /dev/null
+++ b/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/MockMastershipService.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2017-present 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.drivers.netconf;
+
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+
+import org.onosproject.cluster.NodeId;
+import org.onosproject.cluster.RoleInfo;
+import org.onosproject.mastership.MastershipListener;
+import org.onosproject.mastership.MastershipService;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.MastershipRole;
+
+public class MockMastershipService implements MastershipService {
+
+ public MockMastershipService() {
+ }
+
+ @Override
+ public boolean isLocalMaster(DeviceId deviceId) {
+ if (deviceId != null && deviceId.uri().toString().equalsIgnoreCase("netconf:1.2.3.4:830")) {
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public void addListener(MastershipListener listener) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void removeListener(MastershipListener listener) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public MastershipRole getLocalRole(DeviceId deviceId) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public CompletableFuture<MastershipRole> requestRoleFor(DeviceId deviceId) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public CompletableFuture<Void> relinquishMastership(DeviceId deviceId) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public NodeId getMasterFor(DeviceId deviceId) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public RoleInfo getNodesFor(DeviceId deviceId) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Set<DeviceId> getDevicesOf(NodeId nodeId) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
diff --git a/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/MockNetconfController.java b/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/MockNetconfController.java
new file mode 100644
index 0000000..0069eda
--- /dev/null
+++ b/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/MockNetconfController.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2017-present 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.drivers.netconf;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.onlab.packet.Ip4Address;
+import org.onlab.packet.IpAddress;
+import org.onosproject.net.DeviceId;
+import org.onosproject.netconf.NetconfController;
+import org.onosproject.netconf.NetconfDevice;
+import org.onosproject.netconf.NetconfDeviceInfo;
+import org.onosproject.netconf.NetconfDeviceListener;
+import org.onosproject.netconf.NetconfException;
+
+public class MockNetconfController implements NetconfController {
+
+ private Map<DeviceId, NetconfDevice> devicesMap;
+
+ public MockNetconfController() {
+ devicesMap = new HashMap<DeviceId, NetconfDevice>();
+ }
+
+ @Override
+ public void addDeviceListener(NetconfDeviceListener listener) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void removeDeviceListener(NetconfDeviceListener listener) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public NetconfDevice connectDevice(DeviceId deviceId) throws NetconfException {
+ NetconfDevice mockNetconfDevice = null;
+
+ String[] nameParts = deviceId.uri().toASCIIString().split(":");
+ IpAddress ipAddress = Ip4Address.valueOf(nameParts[1]);
+ int port = Integer.parseInt(nameParts[2]);
+ NetconfDeviceInfo ncdi = new NetconfDeviceInfo("mock", "mock", ipAddress, port);
+ try {
+ mockNetconfDevice = (new MockNetconfDeviceFactory()).createNetconfDevice(ncdi);
+ devicesMap.put(deviceId, mockNetconfDevice);
+ } catch (NetconfException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return mockNetconfDevice;
+ }
+
+ @Override
+ public void disconnectDevice(DeviceId deviceId, boolean remove) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void removeDevice(DeviceId deviceId) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public Map<DeviceId, NetconfDevice> getDevicesMap() {
+ return devicesMap;
+ }
+
+ @Override
+ public Set<DeviceId> getNetconfDevices() {
+ return devicesMap.keySet();
+ }
+
+ @Override
+ public NetconfDevice getNetconfDevice(DeviceId deviceInfo) {
+ return devicesMap.get(deviceInfo);
+ }
+
+ @Override
+ public NetconfDevice getNetconfDevice(IpAddress ip, int port) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/MockNetconfDevice.java b/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/MockNetconfDevice.java
new file mode 100644
index 0000000..e99048a
--- /dev/null
+++ b/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/MockNetconfDevice.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2017-present 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.drivers.netconf;
+
+import org.onosproject.netconf.NetconfDevice;
+import org.onosproject.netconf.NetconfDeviceInfo;
+import org.onosproject.netconf.NetconfSession;
+
+public class MockNetconfDevice implements NetconfDevice {
+
+ private boolean active = false;
+ private NetconfSession mockSession = null;
+ private NetconfDeviceInfo mockNetconfDeviceInfo;
+ private Class<? extends NetconfSession> sessionImplClass = MockNetconfSession.class;
+
+ public MockNetconfDevice(NetconfDeviceInfo netconfDeviceInfo) {
+ mockNetconfDeviceInfo = netconfDeviceInfo;
+ }
+
+ //Allows a different implementation of MockNetconfSession to be used.
+ public void setNcSessionImpl(Class<? extends NetconfSession> sessionImplClass) {
+ this.sessionImplClass = sessionImplClass;
+ }
+
+ @Override
+ public boolean isActive() {
+ return active;
+ }
+
+ @Override
+ public NetconfSession getSession() {
+ if (mockSession != null) {
+ return mockSession;
+ }
+
+ try {
+ mockSession =
+ sessionImplClass.getDeclaredConstructor(NetconfDeviceInfo.class).newInstance(mockNetconfDeviceInfo);
+ active = true;
+ return mockSession;
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ @Override
+ public void disconnect() {
+ // TODO Auto-generated method stub
+ mockSession = null;
+ active = false;
+ }
+
+ @Override
+ public NetconfDeviceInfo getDeviceInfo() {
+ // TODO Auto-generated method stub
+ return mockNetconfDeviceInfo;
+ }
+
+}
diff --git a/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/MockNetconfDeviceFactory.java b/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/MockNetconfDeviceFactory.java
new file mode 100644
index 0000000..17b7ff9
--- /dev/null
+++ b/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/MockNetconfDeviceFactory.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2017-present 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.drivers.netconf;
+
+import org.onosproject.netconf.NetconfDevice;
+import org.onosproject.netconf.NetconfDeviceFactory;
+import org.onosproject.netconf.NetconfDeviceInfo;
+import org.onosproject.netconf.NetconfException;
+
+public class MockNetconfDeviceFactory implements NetconfDeviceFactory {
+
+ @Override
+ public NetconfDevice createNetconfDevice(NetconfDeviceInfo netconfDeviceInfo) throws NetconfException {
+ return new MockNetconfDevice(netconfDeviceInfo);
+ }
+
+}
diff --git a/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/MockNetconfSession.java b/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/MockNetconfSession.java
new file mode 100644
index 0000000..cc06407
--- /dev/null
+++ b/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/MockNetconfSession.java
@@ -0,0 +1,408 @@
+/*
+ * Copyright 2016-present 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.drivers.netconf;
+
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.regex.Pattern;
+
+import org.onosproject.netconf.NetconfDeviceInfo;
+import org.onosproject.netconf.NetconfDeviceOutputEventListener;
+import org.onosproject.netconf.NetconfException;
+import org.onosproject.netconf.NetconfSession;
+import org.onosproject.netconf.TargetConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MockNetconfSession implements NetconfSession {
+ private static final Logger log = LoggerFactory
+ .getLogger(MockNetconfSession.class);
+
+ private static final String MESSAGE_ID_STRING = "message-id";
+ private static final String EQUAL = "=";
+ private static final String RPC_OPEN = "<rpc ";
+ private static final String RPC_CLOSE = "</rpc>";
+ private static final String GET_OPEN = "<get>";
+ private static final String GET_CLOSE = "</get>";
+ private static final String NEW_LINE = "\n";
+ private static final String SUBTREE_FILTER_OPEN = "<filter type=\"subtree\">";
+ private static final String SUBTREE_FILTER_CLOSE = "</filter>";
+ private static final String WITH_DEFAULT_OPEN = "<with-defaults ";
+ private static final String WITH_DEFAULT_CLOSE = "</with-defaults>";
+ private static final String EDIT_CONFIG_OPEN = "<edit-config>";
+ private static final String EDIT_CONFIG_CLOSE = "</edit-config>";
+ private static final String COPY_CONFIG_OPEN = "<copy-config>";
+ private static final String COPY_CONFIG_CLOSE = "</copy-config>";
+ private static final String DELETE_CONFIG_OPEN = "<delete-config>";
+ private static final String DELETE_CONFIG_CLOSE = "</delete-config>";
+ private static final String TARGET_OPEN = "<target>";
+ private static final String TARGET_CLOSE = "</target>";
+ private static final String SOURCE_OPEN = "<source>";
+ private static final String SOURCE_CLOSE = "</source>";
+ private static final String DEFAULT_OPERATION_OPEN = "<default-operation>";
+ private static final String DEFAULT_OPERATION_CLOSE = "</default-operation>";
+ private static final String CONFIG_OPEN = "<config xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">";
+ private static final String CONFIG_CLOSE = "</config>";
+
+ private static final String ENDPATTERN = "]]>]]>";
+ private static final String XML_HEADER =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
+ private static final String NETCONF_BASE_NAMESPACE =
+ "xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"";
+ private static final String NETCONF_WITH_DEFAULTS_NAMESPACE =
+ "xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\"";
+
+ private Pattern simpleGetConfig =
+ Pattern.compile("(<\\?xml version=\"1.0\" encoding=\"UTF-8\"\\?>)\\R?"
+ + "(<rpc message-id=\")[0-9]*(\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">)\\R?"
+ + "(<get-config>)\\R?"
+ + "(<source>)\\R?(<running/>)\\R?(</source>)\\R?"
+ + "(</get-config>)\\R?(</rpc>)\\R?(]]>){2}", Pattern.DOTALL);
+
+ private static final String SAMPLE_MSEAEVCUNI_REPLY_INIT = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ + "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"1\">\n"
+ + "<data xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
+ + "</data>\n"
+ + "</rpc-reply>";
+
+
+
+ private NetconfDeviceInfo deviceInfo;
+
+ private final AtomicInteger messageIdInteger = new AtomicInteger(0);
+
+ public MockNetconfSession(NetconfDeviceInfo deviceInfo) throws NetconfException {
+ this.deviceInfo = deviceInfo;
+ }
+
+ @Override
+ public CompletableFuture<String> request(String request) throws NetconfException {
+ throw new NetconfException("Should be calling a higher level command or one that sets the message id");
+ }
+
+ @Override
+ public String get(String request) throws NetconfException {
+
+ return sendRequest(request);
+ }
+
+ @Override
+ public String get(String filterSchema, String withDefaultsMode) throws NetconfException {
+ StringBuilder rpc = new StringBuilder(XML_HEADER);
+ rpc.append(RPC_OPEN);
+ rpc.append(MESSAGE_ID_STRING);
+ rpc.append(EQUAL);
+ rpc.append("\"");
+ rpc.append(messageIdInteger.get());
+ rpc.append("\" ");
+ rpc.append(NETCONF_BASE_NAMESPACE).append(">\n");
+ rpc.append(GET_OPEN).append(NEW_LINE);
+ if (filterSchema != null) {
+ rpc.append(SUBTREE_FILTER_OPEN).append(NEW_LINE);
+ rpc.append(filterSchema).append(NEW_LINE);
+ rpc.append(SUBTREE_FILTER_CLOSE).append(NEW_LINE);
+ }
+ if (withDefaultsMode != null) {
+ rpc.append(WITH_DEFAULT_OPEN).append(NETCONF_WITH_DEFAULTS_NAMESPACE).append(">");
+ rpc.append(withDefaultsMode).append(WITH_DEFAULT_CLOSE).append(NEW_LINE);
+ }
+ rpc.append(GET_CLOSE).append(NEW_LINE);
+ rpc.append(RPC_CLOSE).append(NEW_LINE);
+ rpc.append(ENDPATTERN);
+ String reply = sendRequest(rpc.toString());
+ checkReply(reply);
+ return reply;
+ }
+
+ @Override
+ public String doWrappedRpc(String request) throws NetconfException {
+ StringBuilder rpc = new StringBuilder(XML_HEADER);
+ rpc.append(RPC_OPEN);
+ rpc.append(MESSAGE_ID_STRING);
+ rpc.append(EQUAL);
+ rpc.append("\"");
+ rpc.append(messageIdInteger.get());
+ rpc.append("\" ");
+ rpc.append(NETCONF_BASE_NAMESPACE).append(">\n");
+ rpc.append(request);
+ rpc.append(RPC_CLOSE).append(NEW_LINE);
+ rpc.append(ENDPATTERN);
+ String reply = sendRequest(rpc.toString());
+ checkReply(reply);
+ return reply;
+ }
+
+ @Override
+ public String requestSync(String request) throws NetconfException {
+ if (!request.contains(ENDPATTERN)) {
+ request = request + NEW_LINE + ENDPATTERN;
+ }
+ String reply = sendRequest(request);
+ checkReply(reply);
+ return reply;
+ }
+
+
+ @Override
+ public String getConfig(String targetConfiguration, String configurationSchema) throws NetconfException {
+ return getConfig(TargetConfig.valueOf(targetConfiguration));
+ }
+
+ @Override
+ public String getConfig(String targetConfiguration) throws NetconfException {
+ return getConfig(TargetConfig.valueOf(targetConfiguration), null);
+ }
+
+ @Override
+ public String getConfig(TargetConfig netconfTargetConfig)
+ throws NetconfException {
+ return getConfig(netconfTargetConfig, null);
+ }
+
+ @Override
+ public String getConfig(TargetConfig netconfTargetConfig, String configurationFilterSchema)
+ throws NetconfException {
+ StringBuilder rpc = new StringBuilder(XML_HEADER);
+ rpc.append("<rpc ");
+ rpc.append(MESSAGE_ID_STRING);
+ rpc.append(EQUAL);
+ rpc.append("\"");
+ rpc.append(messageIdInteger.get());
+ rpc.append("\" ");
+ rpc.append("xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n");
+ rpc.append("<get-config>\n");
+ rpc.append("<source>\n");
+ rpc.append("<").append(netconfTargetConfig).append("/>");
+ rpc.append("</source>");
+ if (netconfTargetConfig != null) {
+ rpc.append("<filter type=\"subtree\">\n");
+ rpc.append(configurationFilterSchema).append("\n");
+ rpc.append("</filter>\n");
+ }
+ rpc.append("</get-config>\n");
+ rpc.append("</rpc>\n");
+ rpc.append(ENDPATTERN);
+ String reply = sendRequest(rpc.toString());
+ return checkReply(reply) ? reply : "ERROR " + reply;
+ }
+
+ @Override
+ public boolean editConfig(TargetConfig netconfTargetConfig, String mode, String newConfiguration)
+ throws NetconfException {
+ newConfiguration = newConfiguration.trim();
+ StringBuilder rpc = new StringBuilder(XML_HEADER);
+ rpc.append(RPC_OPEN);
+ rpc.append(MESSAGE_ID_STRING);
+ rpc.append(EQUAL);
+ rpc.append("\"");
+ rpc.append(messageIdInteger.get());
+ rpc.append("\" ");
+ rpc.append(NETCONF_BASE_NAMESPACE).append(">\n");
+ rpc.append(EDIT_CONFIG_OPEN).append("\n");
+ rpc.append(TARGET_OPEN);
+ rpc.append("<").append(netconfTargetConfig).append("/>");
+ rpc.append(TARGET_CLOSE).append("\n");
+ if (mode != null) {
+ rpc.append(DEFAULT_OPERATION_OPEN);
+ rpc.append(mode);
+ rpc.append(DEFAULT_OPERATION_CLOSE).append("\n");
+ }
+ rpc.append(CONFIG_OPEN).append("\n");
+ rpc.append(newConfiguration);
+ rpc.append(CONFIG_CLOSE).append("\n");
+ rpc.append(EDIT_CONFIG_CLOSE).append("\n");
+ rpc.append(RPC_CLOSE);
+ rpc.append(ENDPATTERN);
+ log.debug(rpc.toString());
+ String reply = sendRequest(rpc.toString());
+ return checkReply(reply);
+ }
+
+ @Override
+ public boolean editConfig(String newConfiguration) throws NetconfException {
+ return editConfig(TargetConfig.RUNNING, null, newConfiguration);
+ }
+
+ @Override
+ public boolean editConfig(String targetConfiguration, String mode, String newConfiguration)
+ throws NetconfException {
+ return editConfig(TargetConfig.valueOf(targetConfiguration), mode, newConfiguration);
+ }
+
+ @Override
+ public boolean copyConfig(TargetConfig netconfTargetConfig, String newConfiguration) throws NetconfException {
+ newConfiguration = newConfiguration.trim();
+ StringBuilder rpc = new StringBuilder(XML_HEADER);
+ rpc.append(RPC_OPEN);
+ rpc.append(MESSAGE_ID_STRING);
+ rpc.append(EQUAL);
+ rpc.append("\"");
+ rpc.append(messageIdInteger.get());
+ rpc.append("\" ");
+ rpc.append(NETCONF_BASE_NAMESPACE).append(">\n");
+ rpc.append(COPY_CONFIG_OPEN).append("\n");
+ rpc.append(TARGET_OPEN);
+ rpc.append("<").append(netconfTargetConfig).append("/>");
+ rpc.append(TARGET_CLOSE).append("\n");
+ rpc.append(SOURCE_OPEN);
+ rpc.append("<").append(newConfiguration).append("/>");
+ rpc.append(SOURCE_CLOSE).append("\n");
+ rpc.append(COPY_CONFIG_CLOSE).append("\n");
+ rpc.append(RPC_CLOSE);
+ rpc.append(ENDPATTERN);
+ log.debug(rpc.toString());
+ String reply = sendRequest(rpc.toString());
+ return checkReply(reply);
+ }
+
+ @Override
+ public boolean copyConfig(String targetConfiguration, String newConfiguration) throws NetconfException {
+ return copyConfig(TargetConfig.valueOf(targetConfiguration), newConfiguration);
+ }
+
+ @Override
+ public boolean deleteConfig(TargetConfig netconfTargetConfig) throws NetconfException {
+ StringBuilder rpc = new StringBuilder(XML_HEADER);
+ rpc.append(RPC_OPEN);
+ rpc.append(MESSAGE_ID_STRING);
+ rpc.append(EQUAL);
+ rpc.append("\"");
+ rpc.append(messageIdInteger.get());
+ rpc.append("\" ");
+ rpc.append(NETCONF_BASE_NAMESPACE).append(">\n");
+ rpc.append(DELETE_CONFIG_OPEN).append("\n");
+ rpc.append(TARGET_OPEN);
+ rpc.append("<").append(netconfTargetConfig).append("/>");
+ rpc.append(TARGET_CLOSE).append("\n");
+ rpc.append(DELETE_CONFIG_CLOSE).append("\n");
+ rpc.append(RPC_CLOSE);
+ rpc.append(ENDPATTERN);
+ log.debug(rpc.toString());
+ String reply = sendRequest(rpc.toString());
+ return checkReply(reply);
+ }
+
+ @Override
+ public boolean deleteConfig(String targetConfiguration) throws NetconfException {
+ return deleteConfig(TargetConfig.valueOf(targetConfiguration));
+ }
+
+ @Override
+ public void startSubscription() throws NetconfException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void startSubscription(String filterSchema) throws NetconfException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void endSubscription() throws NetconfException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public boolean lock(String configType) throws NetconfException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean unlock(String configType) throws NetconfException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean lock() throws NetconfException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean unlock() throws NetconfException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean close() throws NetconfException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public String getSessionId() {
+ return "mockSessionId";
+ }
+
+ @Override
+ public String getServerCapabilities() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void setDeviceCapabilities(List<String> capabilities) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void addDeviceOutputListener(NetconfDeviceOutputEventListener listener) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void removeDeviceOutputListener(NetconfDeviceOutputEventListener listener) {
+ // TODO Auto-generated method stub
+
+ }
+
+ private boolean checkReply(String reply) throws NetconfException {
+ if (reply != null) {
+ if (!reply.contains("<rpc-error>")) {
+ log.debug("Device {} sent reply {}", deviceInfo, reply);
+ return true;
+ } else if (reply.contains("<ok/>")
+ || (reply.contains("<rpc-error>")
+ && reply.contains("warning"))) {
+ log.debug("Device {} sent reply {}", deviceInfo, reply);
+ return true;
+ }
+ }
+ log.warn("Device {} has error in reply {}", deviceInfo, reply);
+ return false;
+ }
+
+ private String sendRequest(String request) throws NetconfException {
+ log.info("Mocking NETCONF Session send request: \n" + request);
+
+ if (simpleGetConfig.matcher(request).matches()) {
+ return SAMPLE_MSEAEVCUNI_REPLY_INIT;
+
+ } else {
+ throw new NetconfException("MocknetconfSession. No sendRequest() case for query: " +
+ request);
+ }
+ }
+}
diff --git a/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/NetconfControllerConfigTest.java b/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/NetconfControllerConfigTest.java
new file mode 100644
index 0000000..e108856
--- /dev/null
+++ b/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/NetconfControllerConfigTest.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2017-present 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.drivers.netconf;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onosproject.net.behaviour.ControllerConfig;
+
+public class NetconfControllerConfigTest {
+
+ private ControllerConfig netconfCtlConfig;
+
+ @Before
+ public void setUp() throws Exception {
+ netconfCtlConfig = new NetconfControllerConfig();
+ netconfCtlConfig.setHandler(new MockDriverHandler());
+// netconfCtlConfig.setControllers(Arrays.asList(new ControllerInfo[]{}));
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void testGetControllers() {
+ assertNotNull(netconfCtlConfig.getControllers());
+
+ }
+
+}