ONOS-5304 MDSC TE Tunnel controller

Change-Id: I1edbf3a583966f1389eb167543ced7bd6c4c51b3

ONOS-5304 MDSC TE Tunnel controller

Change-Id: I1edbf3a583966f1389eb167543ced7bd6c4c51b3
diff --git a/apps/actn-mdsc/tetunnel-pce/src/main/java/org/onosproject/actn/mdsc/pce/impl/DefaultTeTunnelPce.java b/apps/actn-mdsc/tetunnel-pce/src/main/java/org/onosproject/actn/mdsc/pce/impl/DefaultTeTunnelPce.java
new file mode 100755
index 0000000..9afdf89
--- /dev/null
+++ b/apps/actn-mdsc/tetunnel-pce/src/main/java/org/onosproject/actn/mdsc/pce/impl/DefaultTeTunnelPce.java
@@ -0,0 +1,45 @@
+/*
+ * 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.actn.mdsc.pce.impl;
+
+import org.onosproject.actn.mdsc.pce.TeTunnelPce;
+import org.onosproject.tetunnel.api.tunnel.TeTunnel;
+import org.onosproject.tetunnel.api.tunnel.path.TeRouteSubobject;
+
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * Default implementation of TE tunnel PCE.
+ */
+class DefaultTeTunnelPce implements TeTunnelPce {
+    @Override
+    public int getPriority() {
+        return PRIORITY_LOWEST - 1;
+    }
+
+    @Override
+    public boolean isSuitable(TeTunnel teTunnel) {
+        return true;
+    }
+
+    @Override
+    public Collection<List<TeRouteSubobject>> computePaths(TeTunnel teTunnel) {
+        //TODO
+        return null;
+    }
+}
diff --git a/apps/actn-mdsc/tetunnel-pce/src/main/java/org/onosproject/actn/mdsc/pce/impl/TeTunnelPceManager.java b/apps/actn-mdsc/tetunnel-pce/src/main/java/org/onosproject/actn/mdsc/pce/impl/TeTunnelPceManager.java
new file mode 100755
index 0000000..68c2af5
--- /dev/null
+++ b/apps/actn-mdsc/tetunnel-pce/src/main/java/org/onosproject/actn/mdsc/pce/impl/TeTunnelPceManager.java
@@ -0,0 +1,86 @@
+/*
+ * 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.actn.mdsc.pce.impl;
+
+import com.google.common.collect.Lists;
+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.Service;
+import org.onosproject.actn.mdsc.pce.TeTunnelPce;
+import org.onosproject.actn.mdsc.pce.TeTunnelPceService;
+import org.onosproject.tetunnel.api.tunnel.TeTunnel;
+import org.onosproject.tetunnel.api.tunnel.path.TeRouteSubobject;
+import org.slf4j.Logger;
+import static org.slf4j.LoggerFactory.getLogger;
+
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * Implementation of Te Tunnel PCE service.
+ */
+@Component(immediate = true)
+@Service
+public class TeTunnelPceManager implements TeTunnelPceService {
+
+    private static final Logger log = getLogger(TeTunnelPceManager.class);
+
+    private List<TeTunnelPce> pces = Lists.newLinkedList();
+
+    @Activate
+    protected void activate() {
+        pces.add(0, new DefaultTeTunnelPce());
+        log.info("Started");
+    }
+
+    @Deactivate
+    protected void deactivate() {
+        log.info("Stopped");
+    }
+
+    @Override
+    public Collection<List<TeRouteSubobject>> computePaths(TeTunnel teTunnel) {
+        TeTunnelPce pce = null;
+        synchronized (pces) {
+            for (TeTunnelPce p : pces) {
+                if (p.isSuitable(teTunnel)) {
+                    pce = p;
+                }
+            }
+        }
+        return pce.computePaths(teTunnel);
+    }
+
+    @Override
+    public Collection<List<TeRouteSubobject>> computePaths(TeTunnel teTunnel,
+                                                           TeTunnelPce pce) {
+        return pce == null ? null : pce.computePaths(teTunnel);
+    }
+
+    @Override
+    public void registerPce(TeTunnelPce pce) {
+        synchronized (pces) {
+            int index = 0;
+            while (pces.get(index).getPriority() > pce.getPriority()) {
+                index++;
+            }
+
+            pces.add(index, pce);
+        }
+    }
+}
diff --git a/apps/actn-mdsc/tetunnel-pce/src/main/java/org/onosproject/actn/mdsc/pce/impl/package-info.java b/apps/actn-mdsc/tetunnel-pce/src/main/java/org/onosproject/actn/mdsc/pce/impl/package-info.java
new file mode 100755
index 0000000..e39e884
--- /dev/null
+++ b/apps/actn-mdsc/tetunnel-pce/src/main/java/org/onosproject/actn/mdsc/pce/impl/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * Implementation of TE tunnel PCE service.
+ */
+package org.onosproject.actn.mdsc.pce.impl;
\ No newline at end of file