Reorganizing ODTN app structure
- separated code which could be referenced from drivers
Change-Id: Ic2c0ae0507abc626771dfaf7a8fc18b5a715cc30
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/behaviour/ConfigurableTransceiver.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/behaviour/ConfigurableTransceiver.java
new file mode 100644
index 0000000..a94f597
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/behaviour/ConfigurableTransceiver.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * 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.odtn.behaviour;
+
+import java.util.List;
+
+import org.onosproject.net.driver.HandlerBehaviour;
+
+import com.google.common.annotations.Beta;
+
+/**
+ * Behaviour for Transceiver.
+ */
+@Beta
+public interface ConfigurableTransceiver extends HandlerBehaviour {
+
+ /**
+ * Generate configuration to enable/disable transceiver.
+ *
+ * @param componentName to enable/disable
+ * @param enable or disable
+ * @return XML documents (List to handle configuration with multiple-roots)
+ */
+ // return type and how component get specified are likely to change in future
+ @Beta
+ List<CharSequence> enable(String componentName, boolean enable);
+}
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/behaviour/OdtnDeviceDescriptionDiscovery.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/behaviour/OdtnDeviceDescriptionDiscovery.java
new file mode 100644
index 0000000..e8657ea
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/behaviour/OdtnDeviceDescriptionDiscovery.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * 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.odtn.behaviour;
+
+import java.util.List;
+
+import org.onosproject.net.device.DeviceDescriptionDiscovery;
+import org.onosproject.net.device.PortDescription;
+
+/**
+ * DeviceDescriptionDiscovery used in ODTN.
+ *
+ * Just declaring certain Annotations will be required.
+ */
+public interface OdtnDeviceDescriptionDiscovery
+ extends DeviceDescriptionDiscovery {
+
+ /**
+ * Annotations key, which stores OpenConfig component name.
+ */
+ String OC_NAME = "oc-name";
+
+ /**
+ * Annotations key, which stores OpenConfig component type.
+ */
+ String OC_TYPE = "oc-type";
+
+ // overriding just to make checkstyle happy
+ @Override
+ List<PortDescription> discoverPortDetails();
+
+}
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/behaviour/PlainTransceiver.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/behaviour/PlainTransceiver.java
new file mode 100644
index 0000000..ae14e07
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/behaviour/PlainTransceiver.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * 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.odtn.behaviour;
+
+import static org.onosproject.odtn.utils.YangToolUtil.toCharSequence;
+import static org.onosproject.odtn.utils.YangToolUtil.toCompositeData;
+import static org.onosproject.odtn.utils.YangToolUtil.toResourceData;
+import static org.onosproject.odtn.utils.YangToolUtil.toXmlCompositeStream;
+
+import java.util.List;
+
+import org.onosproject.net.driver.AbstractHandlerBehaviour;
+import org.onosproject.odtn.utils.openconfig.Transceiver;
+import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.model.ResourceId;
+
+import com.google.common.collect.Lists;
+
+/**
+ * Plain OpenConfig based implementation.
+ */
+public class PlainTransceiver extends AbstractHandlerBehaviour
+ implements ConfigurableTransceiver {
+
+ @Override
+ public List<CharSequence> enable(String componentName, boolean enable) {
+ List<DataNode> nodes = Transceiver.enable(componentName, enable);
+
+ ResourceId empty = ResourceId.builder().build();
+ return Lists.transform(nodes,
+ node -> toCharSequence(toXmlCompositeStream(toCompositeData(toResourceData(empty, node)))));
+ }
+
+}
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/behaviour/package-info.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/behaviour/package-info.java
new file mode 100644
index 0000000..85c8df6
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/behaviour/package-info.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * 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.
+ */
+/**
+ * ODTN Behaviours.
+ */
+package org.onosproject.odtn.behaviour;