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/TeTunnelPce.java b/apps/actn-mdsc/tetunnel-pce/src/main/java/org/onosproject/actn/mdsc/pce/TeTunnelPce.java
new file mode 100755
index 0000000..705896f
--- /dev/null
+++ b/apps/actn-mdsc/tetunnel-pce/src/main/java/org/onosproject/actn/mdsc/pce/TeTunnelPce.java
@@ -0,0 +1,58 @@
+/*
+ * 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;
+
+import org.onosproject.tetunnel.api.tunnel.TeTunnel;
+import org.onosproject.tetunnel.api.tunnel.path.TeRouteSubobject;
+
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * PCE which calculates paths for TE tunnels.
+ */
+public interface TeTunnelPce {
+
+ static final int PRIORITY_HIGHEST = 255;
+ static final int PRIORITY_HIGH = PRIORITY_HIGHEST * 3 / 4;
+ static final int PRIORITY_MEDIUM = PRIORITY_HIGHEST / 2;
+ static final int PRIORITY_LOW = PRIORITY_HIGHEST / 4;
+ static final int PRIORITY_LOWEST = 0;
+
+ /**
+ * Returns priority of this PCE.
+ *
+ * @return priority of this PCE
+ */
+ int getPriority();
+
+ /**
+ * Signifies whether this PCE is suitable for the specified TE tunnel.
+ *
+ * @param teTunnel tunnel to check
+ * @return true if this PCE can calculate path for the TE tunnel
+ */
+ boolean isSuitable(TeTunnel teTunnel);
+
+ /**
+ * Calculates available paths for the specified TE tunnel.
+ *
+ * @param teTunnel tunnel information to be calculated
+ * @return available paths for the specified TE tunnel
+ */
+ Collection<List<TeRouteSubobject>> computePaths(TeTunnel teTunnel);
+}
diff --git a/apps/actn-mdsc/tetunnel-pce/src/main/java/org/onosproject/actn/mdsc/pce/TeTunnelPceService.java b/apps/actn-mdsc/tetunnel-pce/src/main/java/org/onosproject/actn/mdsc/pce/TeTunnelPceService.java
new file mode 100755
index 0000000..a3d10f3
--- /dev/null
+++ b/apps/actn-mdsc/tetunnel-pce/src/main/java/org/onosproject/actn/mdsc/pce/TeTunnelPceService.java
@@ -0,0 +1,58 @@
+/*
+ * 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;
+
+import org.onosproject.tetunnel.api.tunnel.TeTunnel;
+import org.onosproject.tetunnel.api.tunnel.path.TeRouteSubobject;
+
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * TE tunnel PCE management API.
+ */
+public interface TeTunnelPceService {
+
+ /**
+ * Calculates available paths for the specified TE tunnel.
+ * <p>
+ * PCE which is suitable for the specified TE tunnel and with the highest
+ * priority will be chosen for the path calculation.
+ *
+ * @param teTunnel tunnel information to be calculated
+ * @return available paths for the specified TE tunnel
+ */
+ Collection<List<TeRouteSubobject>> computePaths(TeTunnel teTunnel);
+
+ /**
+ * Calculates available paths for the specified TE tunnel with specified
+ * PCE.
+ *
+ * @param teTunnel tunnel information to be calculated
+ * @param pce PCE to be used for path calculation
+ * @return available paths for the specified TE tunnel
+ */
+ Collection<List<TeRouteSubobject>> computePaths(TeTunnel teTunnel,
+ TeTunnelPce pce);
+
+ /**
+ * Registers a new pce.
+ *
+ * @param pce new PCE to be registered.
+ */
+ void registerPce(TeTunnelPce pce);
+}
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
diff --git a/apps/actn-mdsc/tetunnel-pce/src/main/java/org/onosproject/actn/mdsc/pce/package-info.java b/apps/actn-mdsc/tetunnel-pce/src/main/java/org/onosproject/actn/mdsc/pce/package-info.java
new file mode 100644
index 0000000..3f9fb11
--- /dev/null
+++ b/apps/actn-mdsc/tetunnel-pce/src/main/java/org/onosproject/actn/mdsc/pce/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.
+ */
+
+/**
+ * PCE service which calculates paths for TE tunnels.
+ */
+package org.onosproject.actn.mdsc.pce;
\ No newline at end of file