Porting CE app to 4.1
Change-Id: Ic3280ce797f6225773ade789d9793ae445f9f525
diff --git a/LICENSE.txt b/LICENSE.txt
new file mode 100644
index 0000000..761323d
--- /dev/null
+++ b/LICENSE.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright 2017 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.
diff --git a/ce-api/pom.xml b/ce-api/pom.xml
new file mode 100644
index 0000000..5ac4b5d
--- /dev/null
+++ b/ce-api/pom.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2017-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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.opencord</groupId>
+ <artifactId>ce</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>../</relativePath>
+ </parent>
+
+ <groupId>org.opencord.ce</groupId>
+ <artifactId>ce-api</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+
+ <description>Carrier Ethernet service API</description>
+
+ <properties>
+ <onos.app.name>org.opencord.ce.api</onos.app.name>
+ <onos.app.title>Carrier Ethernet service API</onos.app.title>
+ <onos.app.url>http://opencord.org</onos.app.url>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-api</artifactId>
+ <version>1.10.6</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/ce-api/src/main/java/org/opencord/ce/api/models/CarrierEthernetBandwidthProfile.java b/ce-api/src/main/java/org/opencord/ce/api/models/CarrierEthernetBandwidthProfile.java
new file mode 100644
index 0000000..3eeae81
--- /dev/null
+++ b/ce-api/src/main/java/org/opencord/ce/api/models/CarrierEthernetBandwidthProfile.java
@@ -0,0 +1,268 @@
+/*
+ * Copyright 2017-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.opencord.ce.api.models;
+
+
+import org.onlab.util.Bandwidth;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Bandwidth profile for a CE UNI.
+ */
+// TODO: Methods to associate a CE BWP to a generic BWP and a Meter
+public final class CarrierEthernetBandwidthProfile {
+
+ public enum Type {
+ INTERFACE, EVC, COS
+ }
+
+ protected String id;
+ protected String cfgId;
+ protected Type type;
+ protected Bandwidth cir;
+ protected Bandwidth eir;
+ protected long cbs;
+ protected long ebs;
+
+ // TODO: Remove id from constructor - should be generated by some manager
+ private CarrierEthernetBandwidthProfile(String id, String cfgId, Type type,
+ Bandwidth cir, Bandwidth eir,
+ long cbs, long ebs) {
+ checkNotNull(cir, "BW Profile must have an associated CIR");
+ checkNotNull(type, "BW profile must have a type");
+ this.id = id;
+ this.cfgId = cfgId;
+ this.type = type;
+ this.cir = cir;
+ this.eir = eir;
+ this.cbs = cbs;
+ this.ebs = ebs;
+ }
+
+ /**
+ * Returns BWP string identifier.
+ *
+ * @return BWP string identifier
+ */
+ public String id() {
+ return id;
+ }
+
+ /**
+ * Returns BWP string config identifier.
+ *
+ * @return BWP string config identifier
+ */
+ public String cfgId() {
+ return cfgId;
+ }
+
+ /**
+ * Returns BWP type (INTERFACE, EVC, COS).
+ *
+ * @return BWP type
+ */
+ public Type type() {
+ return type;
+ }
+
+ /**
+ * Returns BWP CIR rate.
+ *
+ * @return BWP CIR rate
+ */
+ public Bandwidth cir() {
+ return cir;
+ }
+
+ /**
+ * Returns BWP EIR rate.
+ *
+ * @return BWP EIR rate
+ */
+ public Bandwidth eir() {
+ return eir;
+ }
+
+ /**
+ * Returns BWP CBS in Bytes.
+ *
+ * @return BWP CBS in Bytes
+ */
+ public long cbs() {
+ return cbs;
+ }
+
+ /**
+ * Returns BWP EBS in Bytes.
+ *
+ * @return BWP EBS in Bytes
+ */
+ public long ebs() {
+ return ebs;
+ }
+
+ /**
+ * Sets BWP id.
+ *
+ * @param id the id to set
+ */
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ /**
+ * Sets BWP CIR rate.
+ *
+ * @param cir the CIR to set
+ */
+ public void setCir(Bandwidth cir) {
+ this.cir = cir;
+ }
+
+ /**
+ * Sets BWP EIR rate.
+ *
+ * @param eir the EIR to set
+ */
+ public void setEir(Bandwidth eir) {
+ this.eir = eir;
+ }
+
+ public String toString() {
+
+ return toStringHelper(this)
+ .add("id", id)
+ .add("type", type)
+ .add("cir", cir)
+ .add("cbs", cbs)
+ .add("eir", eir)
+ .add("ebs", ebs).toString();
+ }
+
+ /**
+ * Returns a new builder.
+ *
+ * @return new builder
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ /**
+ * Builder of CarrierEthernetBandwidthProfile entities.
+ */
+ public static final class Builder {
+
+ String id;
+ String cfgId;
+ Type type;
+ Bandwidth cir;
+ Bandwidth eir;
+ long cbs;
+ long ebs;
+
+ /**
+ * Sets the id of this builder.
+ *
+ * @param id the builder id to set
+ * @return this builder instance
+ */
+ public Builder id(String id) {
+ this.id = id;
+ return this;
+ }
+
+ /**
+ * Sets the cfgId of this builder.
+ *
+ * @param cfgId the builder cfgId to set
+ * @return this builder instance
+ */
+ public Builder cfgId(String cfgId) {
+ this.cfgId = cfgId;
+ return this;
+ }
+
+ /**
+ * Sets the type of this builder.
+ *
+ * @param type the builder type to set
+ * @return this builder instance
+ */
+ public Builder type(Type type) {
+ this.type = type;
+ return this;
+ }
+
+ /**
+ * Sets the cir of this builder.
+ *
+ * @param cir the builder cir to set
+ * @return this builder instance
+ */
+ public Builder cir(Bandwidth cir) {
+ this.cir = cir;
+ return this;
+ }
+
+ /**
+ * Sets the eir of this builder.
+ *
+ * @param eir the builder eir to set
+ * @return this builder instance
+ */
+ public Builder eir(Bandwidth eir) {
+ this.eir = eir;
+ return this;
+ }
+
+ /**
+ * Sets the cbs of this builder.
+ *
+ * @param cbs the builder cbs to set
+ * @return this builder instance
+ */
+ public Builder cbs(long cbs) {
+ this.cbs = cbs;
+ return this;
+ }
+
+ /**
+ * Sets the ebs of this builder.
+ *
+ * @param ebs the builder ebs to set
+ * @return this builder instance
+ */
+ public Builder ebs(long ebs) {
+ this.ebs = ebs;
+ return this;
+ }
+
+ /**
+ * Builds a new CarrierEthernetBandwidthProfile instance based on this builder's parameters.
+ *
+ * @return a new CarrierEthernetBandwidthProfile instance
+ */
+ public CarrierEthernetBandwidthProfile build() {
+ return new CarrierEthernetBandwidthProfile(id, cfgId, type, cir, eir, cbs, ebs);
+ }
+ }
+}
+
diff --git a/ce-api/src/main/java/org/opencord/ce/api/models/CarrierEthernetConnection.java b/ce-api/src/main/java/org/opencord/ce/api/models/CarrierEthernetConnection.java
new file mode 100644
index 0000000..ce4b1ed
--- /dev/null
+++ b/ce-api/src/main/java/org/opencord/ce/api/models/CarrierEthernetConnection.java
@@ -0,0 +1,153 @@
+/*
+ * Copyright 2017-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.opencord.ce.api.models;
+
+import java.time.Duration;
+
+/**
+ * Representation of an abstract CE connection (meant to be extended by the EVC and FC classes).
+ */
+public abstract class CarrierEthernetConnection {
+
+ public enum Type {
+ POINT_TO_POINT, // E-LINE
+ MULTIPOINT_TO_MULTIPOINT, // E-LAN
+ ROOT_MULTIPOINT // E_TREE
+ }
+
+ public enum State {
+ ACTIVE,
+ INACTIVE,
+ PARTIAL
+ }
+
+ protected EvcConnId id;
+ protected String cfgId;
+ protected Type type;
+ protected State state;
+ protected Duration maxLatency;
+
+ private static final Duration DEFAULT_MAX_LATENCY = Duration.ofMillis(50);
+
+ // Note: id should be provided only when updating an existing connection
+ public CarrierEthernetConnection(EvcConnId id, String cfgId, Type type, Duration maxLatency) {
+ this.id = id;
+ this.cfgId = cfgId;
+ this.type = type;
+ this.state = State.INACTIVE;
+ this.maxLatency = maxLatency == null ? DEFAULT_MAX_LATENCY : maxLatency;
+ }
+
+ /**
+ * Returns connection identifier.
+ *
+ * @return connection identifier
+ */
+ public EvcConnId id() {
+ return id;
+ }
+
+ /**
+ * Returns connection config identifier.
+ *
+ * @return connection config identifier
+ */
+ public String cfgId() {
+ return cfgId;
+ }
+
+ /**
+ * Returns type of connection.
+ *
+ * @return type of connection
+ */
+ public Type type() {
+ return type;
+ }
+
+ /**
+ * Returns connectivity state of the connection.
+ *
+ * @return connectivity state
+ */
+ public State state() {
+ return state;
+ }
+
+ /**
+ * Indicates whether the connection is active or partially active.
+ *
+ * @return connectivity state
+ */
+ public boolean isActive() {
+ return !state.equals(State.INACTIVE);
+ }
+
+ /**
+ * Returns maximum latency constraint.
+ *
+ * @return maximum latency constraint
+ */
+ public Duration maxLatency() {
+ return maxLatency;
+ }
+
+ /**
+ * Sets connection identifier.
+ *
+ * @param id the connection identifier to set
+ */
+ public void setId(EvcConnId id) {
+ this.id = id;
+ }
+
+ /**
+ * Sets connection config identifier.
+ *
+ * @param cfgId connection config identifier
+ */
+ public void setCfgId(String cfgId) {
+ this.cfgId = cfgId;
+ }
+
+ /**
+ * Sets the connectivity state of the connection.
+ *
+ * @param state the connectivity state to set
+ */
+ public void setState(State state) {
+ this.state = state;
+ }
+
+ /**
+ * Sets the type of connection.
+ *
+ * @param type type of connection to set
+ */
+ public void setType(Type type) {
+ this.type = type;
+ }
+
+ /**
+ * Sets maximum latency constraint.
+ *
+ * @param maxLatency the maximum latency constraint to set
+ */
+ public void setMaxLatency(Duration maxLatency) {
+ this.maxLatency = maxLatency;
+ }
+}
diff --git a/ce-api/src/main/java/org/opencord/ce/api/models/CarrierEthernetEnni.java b/ce-api/src/main/java/org/opencord/ce/api/models/CarrierEthernetEnni.java
new file mode 100644
index 0000000..15659d6
--- /dev/null
+++ b/ce-api/src/main/java/org/opencord/ce/api/models/CarrierEthernetEnni.java
@@ -0,0 +1,326 @@
+/*
+ * Copyright 2017-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.opencord.ce.api.models;
+
+
+import com.google.common.collect.Sets;
+import org.onlab.packet.VlanId;
+import org.onlab.util.Bandwidth;
+import org.onosproject.net.Annotations;
+import org.onosproject.net.ConnectPoint;
+import org.slf4j.Logger;
+
+import java.util.Set;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Representation of a Carrier Ethernet ENNI.
+ * Class can be used in different two ways:
+ * 1. As a global ENNI descriptor containing one or more S-VLAN tags
+ * 2. As a service-specific ENNI descriptor containing a single S-VLAN tag and including a role (e.g. hub, spoke)
+ */
+public final class CarrierEthernetEnni extends CarrierEthernetNetworkInterface {
+
+ private final Logger log = getLogger(getClass());
+
+ public enum Role {
+
+ HUB("Hub"),
+ SPOKE("Spoke"),
+ // FIXME: Remove these after LTP-NI role mapping is fixed
+ ROOT("Root"),
+ LEAF("Leaf");
+
+ private String value;
+
+ Role(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public String toString() {
+ return value;
+ }
+ }
+
+ protected Role role;
+ protected Set<VlanId> sVlanIdSet;
+ String tpid;
+
+ private CarrierEthernetEnni(ConnectPoint cp, String uniCfgId,
+ Role role, VlanId sVlanId, String tpid,
+ Bandwidth usedCapacity, Annotations...annotations) {
+ super(cp, Type.ENNI, uniCfgId, annotations);
+ // TODO: Check for null
+ this.role = role;
+ this.sVlanIdSet = Sets.newConcurrentHashSet();
+ // The following applies only to service-specific ENNIs
+ if (sVlanId != null) {
+ this.sVlanIdSet.add(sVlanId);
+ // TODO: Use Hub/Spoke role correctly
+ this.role = Role.HUB;
+ this.usedCapacity = usedCapacity;
+ this.tpid = tpid;
+ }
+ }
+
+ /**
+ * Adds the resources associated with an FC-specific ENNI to a global ENNI.
+ *
+ * @param enni the FC-specific ENNI to be added
+ */
+ @Override
+ public void addEcNi(CarrierEthernetNetworkInterface enni) {
+ // Add S-VLAN ID
+ if (enni.sVlanId() != VlanId.NONE) {
+ this.sVlanIdSet.add(enni.sVlanId());
+ }
+ // Used capacity cannot be more than ENNI capacity
+ this.usedCapacity = Bandwidth.bps(Math.min(this.usedCapacity.bps() + enni.usedCapacity().bps(),
+ this.capacity.bps()));
+ }
+
+ /**
+ * Removes the resources associated with an FC-specific ENNI from a global ENNI.
+ *
+ * @param enni the FC-specific ENNI to be removed
+ */
+ @Override
+ public void removeEcNi(CarrierEthernetNetworkInterface enni) {
+ // Remove UNI CE-VLAN ID
+ sVlanIdSet.remove(enni.sVlanId());
+ // Redundant check - should be avoided by check in validateBwp
+ this.usedCapacity = Bandwidth.bps(Math.max(this.usedCapacity.bps() - enni.usedCapacity().bps(), 0));
+ }
+
+ /**
+ * Validates whether an FC-specific ENNI is compatible with the corresponding global ENNI.
+ *
+ * @param enni the FC-specific ENNI
+ * @return boolean value indicating whether the ENNIs are compatible
+ */
+ @Override
+ public boolean validateEcNi(CarrierEthernetNetworkInterface enni) {
+
+ // Check if the S-VLAN ID of the ENNI is already included in global ENNI
+ if (enni.sVlanId() != VlanId.NONE) {
+ if (sVlanIdSet.contains(enni.sVlanId())) {
+ log.error("S-VLAN ID {} already exists in ENNI {}", enni.sVlanId().toString(), this.id());
+ return false;
+ }
+ }
+
+ // Check whether there are enough available resources on the ENNI
+ if (usedCapacity.bps() + enni.usedCapacity().bps() > capacity.bps()) {
+ log.error("ENNI {} cannot be added to global ENNI {} due to lack of resources", enni.id(), this.id());
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Returns ENNI role - applicable only to service-specific ENNIs.
+ *
+ * @return ENNI role
+ */
+ @Override
+ public Role role() {
+ return role;
+ }
+
+ /**
+ * Returns the S-VLAN id associated with a service ENNI,
+ * or the first S-VLAN ID found for a global ENNI.
+ * This is assumed to be the S-TAG of another FC interconnected with this ENNI.
+ *
+ * @return S-VLAN id
+ */
+ @Override
+ public VlanId sVlanId() {
+ if (sVlanIdSet.isEmpty()) {
+ return VlanId.NONE;
+ } else {
+ return sVlanIdSet.iterator().next();
+ }
+ }
+
+ /**
+ * Always returns null, since CE-VLAN IDs are not associated with ENNIs.
+ *
+ * @return null
+ */
+ @Override
+ public VlanId ceVlanId() {
+ return null;
+ }
+
+ /**
+ * Returns ENNI tpid - applicable only to service-specific ENNIs.
+ *
+ * @return tpid
+ */
+ public String tpid() {
+ return tpid;
+ }
+
+ /**
+ * Returns the set of S-VLAN ids associated with the ENNI.
+ * Those are assumed to be the S-TAGs of other FCs interconnected with this ENNI.
+ *
+ * @return S-VLAN id set
+ */
+ public Set<VlanId> sVlanIdSet() {
+ return sVlanIdSet;
+ }
+
+ // FIXME: Find a better way to implement this method
+ /**
+ * Sets the S-VLAN id associated with an FC INNI.
+ *
+ * @param sVlanId S-VLAN id to set
+ */
+ public void setSVlanId(VlanId sVlanId) {
+ sVlanIdSet.add(sVlanId);
+ }
+
+ @Override
+ public String toString() {
+
+ return toStringHelper(this)
+ .add("id", this.id)
+ .add("cfgId", this.cfgId)
+ .add("role", role)
+ .add("refCount", refCount)
+ .add("sVlanIds", sVlanIdSet)
+ .add("capacity", this.capacity)
+ .add("usedCapacity", this.usedCapacity).toString();
+ }
+
+ /**
+ * Returns a new builder.
+ *
+ * @return new builder
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ /**
+ * Builder of CarrierEthernetEnni entities.
+ */
+ public static final class Builder {
+
+ private ConnectPoint cp;
+ private String cfgId;
+ private Role role;
+ private VlanId sVlanId;
+ private String tpid;
+ private Bandwidth usedCapacity;
+ private Annotations annotations;
+
+ /**
+ * Sets the cp of this builder.
+ *
+ * @param cp the builder cp to set
+ * @return this builder instance
+ */
+ public Builder cp(ConnectPoint cp) {
+ this.cp = cp;
+ return this;
+ }
+
+ /**
+ * Sets the cfgId of this builder.
+ *
+ * @param cfgId the builder cfgId to set
+ * @return this builder instance
+ */
+ public Builder cfgId(String cfgId) {
+ this.cfgId = cfgId;
+ return this;
+ }
+
+ /**
+ * Sets the role of this builder.
+ *
+ * @param role the builder role to set
+ * @return this builder instance
+ */
+ public Builder role(Role role) {
+ this.role = role;
+ return this;
+ }
+
+ /**
+ * Sets the sVlanId of this builder.
+ *
+ * @param sVlanId the builder sVlanId to set
+ * @return this builder instance
+ */
+ public Builder sVlanId(VlanId sVlanId) {
+ this.sVlanId = sVlanId;
+ return this;
+ }
+
+ /**
+ * Sets the tpid of this builder.
+ *
+ * @param tpid the builder tpid to set
+ * @return this builder instance
+ */
+ public Builder tpid(String tpid) {
+ this.tpid = tpid;
+ return this;
+ }
+
+ /**
+ * Sets the usedCapacity of this builder.
+ *
+ * @param usedCapacity the builder usedCapacity to set
+ * @return this builder instance
+ */
+ public Builder usedCapacity(Bandwidth usedCapacity) {
+ this.usedCapacity = usedCapacity;
+ return this;
+ }
+
+ /**
+ * Sets annotations.
+ *
+ * @param annotations annotations
+ * @return this builder instance
+ */
+ public Builder annotations(Annotations annotations) {
+ this.annotations = annotations;
+ return this;
+ }
+
+ /**
+ * Builds a new CarrierEthernetEnni instance.
+ * based on this builder's parameters
+ *
+ * @return a new CarrierEthernetEnni instance
+ */
+ public CarrierEthernetEnni build() {
+ return new CarrierEthernetEnni(cp, cfgId, role, sVlanId, tpid, usedCapacity, annotations);
+ }
+ }
+}
+
diff --git a/ce-api/src/main/java/org/opencord/ce/api/models/CarrierEthernetEvcUtils.java b/ce-api/src/main/java/org/opencord/ce/api/models/CarrierEthernetEvcUtils.java
new file mode 100644
index 0000000..dd59c42
--- /dev/null
+++ b/ce-api/src/main/java/org/opencord/ce/api/models/CarrierEthernetEvcUtils.java
@@ -0,0 +1,176 @@
+/*
+ * Copyright 2017-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.opencord.ce.api.models;
+
+
+import org.onlab.packet.VlanId;
+import org.onlab.util.Bandwidth;
+import org.onosproject.net.ConnectPoint;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import static org.opencord.ce.api.models.CarrierEthernetVirtualConnection.MAX_NUM_UNI;
+
+/**
+ * Utilities to build EthernetVirtualConnections.
+ */
+public final class CarrierEthernetEvcUtils {
+
+ // no instantiation
+ private CarrierEthernetEvcUtils() {
+ }
+
+ /**
+ * Return the CE-VLAN ID for the CE evc based on the CLI-supplied argument.
+ *
+ * @param argCeVlanId vlanID
+ * @return CE-VLAN ID for the CE evc
+ */
+ public static VlanId generateCeVlanId(short argCeVlanId) {
+ return ((argCeVlanId == -1) ? null : VlanId.vlanId(argCeVlanId));
+ }
+
+ /**
+ * Return the CE evc type based on the CLI-supplied arguments.
+ *
+ * @param evcTypeString EVC type
+ * @param uniList UNIs list
+ * @return the CE evc type
+ */
+ public static CarrierEthernetConnection.Type generateEvcType(String evcTypeString, List<String> uniList) {
+ if (evcTypeString == null) {
+ return ((uniList.size() > 2) ?
+ CarrierEthernetConnection.Type.MULTIPOINT_TO_MULTIPOINT :
+ CarrierEthernetConnection.Type.POINT_TO_POINT);
+ } else {
+ // TODO: Catch exception
+ return CarrierEthernetConnection.Type.valueOf(evcTypeString);
+ }
+ }
+
+ /**
+ * Return the EVC maxNumUni parameter based on the CLI-supplied arguments.
+ *
+ * @param maxNumUni maximum numbers of UNIs
+ * @param evcTypeString EVC Type
+ * @param uniList UNIs list
+ * @return the maxNumUni parameter
+ */
+ public static Integer generateMaxNumUni(int maxNumUni, String evcTypeString, List<String> uniList) {
+ if (maxNumUni == -1) {
+ if (evcTypeString == null) {
+ return ((uniList.size() > 2) ?
+ MAX_NUM_UNI : 2);
+ } else {
+ // TODO: Catch exception
+ CarrierEthernetConnection.Type evcType =
+ CarrierEthernetConnection.Type.valueOf(evcTypeString);
+ return (evcType.equals(CarrierEthernetConnection.Type.POINT_TO_POINT) ? 2 :
+ MAX_NUM_UNI);
+ }
+ } else {
+ return maxNumUni;
+ }
+ }
+
+ /**
+ * Return the BW profile type based on the CLI-supplied arguments.
+ *
+ * @param ceVlanId vlanID
+ * @return the BWP profile type
+ */
+ public static CarrierEthernetBandwidthProfile.Type generateBandwidthProfileType(short ceVlanId) {
+ // TODO: Add the CoS BW profile case
+ return ((ceVlanId == -1) ?
+ CarrierEthernetBandwidthProfile.Type.INTERFACE : CarrierEthernetBandwidthProfile.Type.EVC);
+ }
+
+ /**
+ * Return the BW profile id based on the CLI-supplied arguments.
+ *
+ * @param uniId UNI id
+ * @param evcCfgId EVC configuration Id
+ * @param ceVlanId vlanID
+ * @return the BW profile id
+ */
+ public static String generateBandwidthProfileId(String uniId, String evcCfgId, int ceVlanId) {
+ // TODO: Add the CoS BW profile case
+ return ((ceVlanId == -1) ? uniId : evcCfgId);
+ }
+
+ /**
+ * Return the set of UNIs for the CE EVC based on the CLI-supplied arguments.
+ *
+ * @param evcTypeString Type of the UNI
+ * @param uniList list of remaning UNIs
+ * @param ceVlanId vlanID
+ * @param firstUni first UNI id
+ * @param evcCfgId EVC configuration Id
+ * @param cir The CIR in Mbps
+ * @param eir The EIR in Mbps
+ * @param cbs The CBS in Byte
+ * @param ebs The EBS in Byte
+ * @return the set of UNIs for the CE EVC
+ */
+ public static Set<CarrierEthernetUni> generateUniSet(String evcTypeString, List<String> uniList,
+ short ceVlanId, String firstUni, String evcCfgId,
+ Double cir, Double eir, Long cbs, Long ebs) {
+
+ Set<CarrierEthernetUni> uniSet = new HashSet<>();
+
+ CarrierEthernetConnection.Type evcType = generateEvcType(evcTypeString, uniList);
+
+ // We assume that first UNI supplied is always root
+ uniSet.add(CarrierEthernetUni.builder()
+ .cp(ConnectPoint.deviceConnectPoint(firstUni))
+ .role(CarrierEthernetUni.Role.ROOT)
+ .ceVlanId(generateCeVlanId(ceVlanId))
+ .bwp(CarrierEthernetBandwidthProfile.builder()
+ .id(generateBandwidthProfileId(firstUni, evcCfgId, ceVlanId))
+ .type(generateBandwidthProfileType(ceVlanId))
+ .cir(Bandwidth.mbps(cir))
+ .eir(Bandwidth.mbps(eir))
+ .cbs(cbs)
+ .ebs(ebs)
+ .build())
+ .build());
+
+ final CarrierEthernetUni.Role role;
+ // For E-Line and E-LAN all UNIs are roots. For E-Tree all UNIs are leafs except from one
+ role = ((evcType == CarrierEthernetConnection.Type.ROOT_MULTIPOINT) ?
+ CarrierEthernetUni.Role.LEAF : CarrierEthernetUni.Role.ROOT);
+
+ uniList.forEach(argUni -> uniSet.add(
+ CarrierEthernetUni.builder()
+ .cp(ConnectPoint.deviceConnectPoint(argUni))
+ .role(role)
+ .ceVlanId(generateCeVlanId(ceVlanId))
+ .bwp(CarrierEthernetBandwidthProfile.builder()
+ .id(generateBandwidthProfileId(argUni, evcCfgId, ceVlanId))
+ .type(generateBandwidthProfileType(ceVlanId))
+ .cir(Bandwidth.mbps(cir))
+ .eir(Bandwidth.mbps(eir))
+ .cbs(cbs)
+ .ebs(ebs)
+ .build())
+ .build()));
+
+ return uniSet;
+ }
+}
diff --git a/ce-api/src/main/java/org/opencord/ce/api/models/CarrierEthernetForwardingConstruct.java b/ce-api/src/main/java/org/opencord/ce/api/models/CarrierEthernetForwardingConstruct.java
new file mode 100644
index 0000000..e4e4ddc
--- /dev/null
+++ b/ce-api/src/main/java/org/opencord/ce/api/models/CarrierEthernetForwardingConstruct.java
@@ -0,0 +1,221 @@
+/*
+ * Copyright 2017-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.opencord.ce.api.models;
+
+import org.onlab.packet.VlanId;
+
+import java.time.Duration;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Collectors;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Representation of a CE Forwarding Construct.
+ */
+public final class CarrierEthernetForwardingConstruct extends CarrierEthernetConnection {
+
+ private Set<CarrierEthernetLogicalTerminationPoint> ltpSet;
+ private VlanId vlanId;
+ private boolean congruentPaths = true;
+ protected AtomicInteger refCount;
+
+ // TODO: Remove id from constructor - currently used only when updating FC
+ // TODO: Add congruentPaths flag to constructor and Builder
+ private CarrierEthernetForwardingConstruct(EvcConnId id, String cfgId, Type type,
+ Set<CarrierEthernetLogicalTerminationPoint> ltpSet,
+ Duration maxLatency) {
+ super(id, cfgId, type, maxLatency);
+ this.ltpSet = new HashSet<>(ltpSet);
+ this.vlanId = null;
+ this.refCount = new AtomicInteger();
+ }
+
+ /**
+ * Returns Vlan id.
+ *
+ * @return Vlan id
+ */
+ public VlanId vlanId() {
+ return vlanId;
+ }
+
+
+ /**
+ * Returns the set of LTPs associated with the FC.
+ *
+ * @return set of LTPs associated with the FC
+ */
+ public Set<CarrierEthernetLogicalTerminationPoint> ltpSet() {
+ return ltpSet;
+ }
+
+ /**
+ * Returns the set of UNIs associated with the FC.
+ *
+ * @return set of UNIs associated with the FC
+ */
+ public Set<CarrierEthernetUni> uniSet() {
+ // FIXME: Find a more efficient way to get the FC UNIs
+ return ltpSet
+ .stream()
+ .filter(ltp -> ltp.type().equals(CarrierEthernetNetworkInterface.Type.UNI))
+ .map(ltp -> (CarrierEthernetUni) ltp.ni()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Returns true if FC requires that both directions should use the same path.
+ *
+ * @return true if both directions should use the same path
+ */
+ public boolean congruentPaths() {
+ return congruentPaths;
+ }
+
+ /**
+ * Returns counter with the number of references (from EVCs) to the particular FC.
+ *
+ * @return number of references counter
+ */
+ public AtomicInteger refCount() {
+ return refCount;
+ }
+
+ /**
+ * Sets the vlanId to be used by the FC.
+ *
+ * @param vlanId the vlanId to set
+ */
+ public void setVlanId(VlanId vlanId) {
+ this.vlanId = vlanId;
+ }
+
+ /**
+ * Sets the set of LTPs.
+ *
+ * @param ltpSet the set of LTPs to be set
+ */
+ public void setLtpSet(Set<CarrierEthernetLogicalTerminationPoint> ltpSet) {
+ this.ltpSet = ltpSet;
+ }
+
+ public String toString() {
+
+ return toStringHelper(this)
+ .add("id", id)
+ .add("cfgId", cfgId)
+ .add("type", type)
+ .add("vlanId", vlanId)
+ .add("refCount", refCount)
+ .add("LTPs", ltpSet).toString();
+ }
+
+ /**
+ * Returns a new builder.
+ *
+ * @return new builder
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ /**
+ * Builder of CarrierEthernetForwardingConstruct entities.
+ */
+ public static final class Builder {
+
+ private EvcConnId id;
+ private String cfgId;
+ private Type type;
+ private Duration maxLatency;
+ private Set<CarrierEthernetLogicalTerminationPoint> ltpSet;
+
+ /**
+ * Sets the id of this builder.
+ *
+ * @param id the builder id to set
+ * @return this builder instance
+ */
+ public Builder id(EvcConnId id) {
+ this.id = id;
+ return this;
+ }
+
+ /**
+ * Sets the cfgId of this builder.
+ *
+ * @param cfgId the builder cfgId to set
+ * @return this builder instance
+ */
+ public Builder cfgId(String cfgId) {
+ this.cfgId = cfgId;
+ return this;
+ }
+
+ /**
+ * Sets the type of this builder.
+ *
+ * @param type the builder type to set
+ * @return this builder instance
+ */
+ public Builder type(Type type) {
+ this.type = type;
+ return this;
+ }
+
+ /**
+ * Sets the maxLatency of this builder.
+ *
+ * @param maxLatency the builder maxLatency to set
+ * @return this builder instance
+ */
+ public Builder maxLatency(Duration maxLatency) {
+ this.maxLatency = maxLatency;
+ return this;
+ }
+
+ /**
+ * Sets the ltpSet of this builder.
+ *
+ * @param ltpSet the builder ltpSet to set
+ * @return this builder instance
+ */
+ public Builder ltpSet(Set<CarrierEthernetLogicalTerminationPoint> ltpSet) {
+ this.ltpSet = ltpSet;
+ return this;
+ }
+
+ /**
+ * Builds a new CarrierEthernetForwardingConstruct instance.
+ * based on this builder's parameters
+ *
+ * @return a new CarrierEthernetForwardingConstruct instance
+ */
+ public CarrierEthernetForwardingConstruct build() {
+ checkNotNull(type, "FC must have a type");
+ checkArgument(ltpSet != null && ltpSet.size() > 1,
+ "FC must include at least two LTPs");
+
+ return new CarrierEthernetForwardingConstruct(id, cfgId, type, ltpSet, maxLatency);
+ }
+ }
+}
+
diff --git a/ce-api/src/main/java/org/opencord/ce/api/models/CarrierEthernetGenericNi.java b/ce-api/src/main/java/org/opencord/ce/api/models/CarrierEthernetGenericNi.java
new file mode 100644
index 0000000..e543a07
--- /dev/null
+++ b/ce-api/src/main/java/org/opencord/ce/api/models/CarrierEthernetGenericNi.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright 2017-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.opencord.ce.api.models;
+
+
+import org.onlab.packet.VlanId;
+import org.onosproject.net.Annotations;
+import org.onosproject.net.ConnectPoint;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+
+/**
+ * Representation of a Generic Carrier Ethernet NI.
+ * Class is only meant to be used for establishing forwarding in CarrierEthernetPacketNodeManagers
+ */
+public class CarrierEthernetGenericNi extends CarrierEthernetNetworkInterface {
+
+ public enum Role {
+
+ NONE("None");
+
+ private String value;
+
+ Role(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public String toString() {
+ return value;
+ }
+ }
+
+ public CarrierEthernetGenericNi(ConnectPoint connectPoint, String uniCfgId,
+ Annotations...annotations) {
+ super(connectPoint, Type.GENERIC, uniCfgId, annotations);
+ }
+
+ @Override
+ public Role role() {
+ return Role.NONE;
+ }
+
+ /**
+ * Always returns null, since CE-VLAN IDs are not associated with Generic NIs.
+ *
+ * @return null
+ */
+ @Override
+ public VlanId ceVlanId() {
+ return null;
+ }
+
+ /**
+ * Always returns null, since S-TAGs are not associated with Generic NIs.
+ *
+ * @return null
+ */
+ @Override
+ public VlanId sVlanId() {
+ return null;
+ }
+
+ /**
+ * Dummy implementation of abstract method (for generic NI type there is no concept of EVC vs. global NIs).
+ *
+ * @param gni a generic NI
+ */
+ @Override
+ public void addEcNi(CarrierEthernetNetworkInterface gni) {}
+
+ /**
+ * Dummy implementation of abstract method (for generic NI type there is no concept of EVC vs. global NIs).
+ *
+ * @param gni a generic NI
+ */
+ @Override
+ public void removeEcNi(CarrierEthernetNetworkInterface gni) {}
+
+ /**
+ * Dummy implementation of abstract method (for generic NI type there is no concept of EVC vs. global NIs).
+ *
+ * @param gni a generic NI
+ * @return true
+ */
+ @Override
+ public boolean validateEcNi(CarrierEthernetNetworkInterface gni) {
+ return true;
+ }
+
+ @Override
+ public String toString() {
+
+ return toStringHelper(this)
+ .add("id", this.id)
+ .add("cfgId", this.cfgId)
+ .add("refCount", refCount)
+ .add("capacity", this.capacity)
+ .add("usedCapacity", this.usedCapacity).toString();
+ }
+
+}
+
diff --git a/ce-api/src/main/java/org/opencord/ce/api/models/CarrierEthernetInni.java b/ce-api/src/main/java/org/opencord/ce/api/models/CarrierEthernetInni.java
new file mode 100644
index 0000000..ec49e88
--- /dev/null
+++ b/ce-api/src/main/java/org/opencord/ce/api/models/CarrierEthernetInni.java
@@ -0,0 +1,333 @@
+/*
+ * Copyright 2017-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.opencord.ce.api.models;
+
+
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Sets;
+import org.onlab.packet.VlanId;
+import org.onlab.util.Bandwidth;
+import org.onosproject.net.Annotations;
+import org.onosproject.net.ConnectPoint;
+import org.slf4j.Logger;
+
+import java.util.Set;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Representation of a Carrier Ethernet INNI.
+ * Class can be used in different two ways:
+ * 1. As a global INNI descriptor containing one or more S-VLAN tags
+ * 2. As a service-specific INNI descriptor containing a single S-VLAN tag and including a role (e.g. hub, spoke)
+ */
+public final class CarrierEthernetInni extends CarrierEthernetNetworkInterface {
+
+ private final Logger log = getLogger(getClass());
+
+ public enum Role {
+
+ HUB("Hub"),
+ // FIXME: Remove that after hackathon?
+ TRUNK("Trunk"),
+ SPOKE("Spoke"),
+ // FIXME: Remove these after LTP-NI role mapping is fixed
+ ROOT("Root"),
+ LEAF("Leaf");
+
+ private String value;
+
+ Role(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public String toString() {
+ return value;
+ }
+ }
+
+ protected Role role;
+ protected Set<VlanId> sVlanIdSet;
+ // TODO: Associate TPIDs with S-TAGs
+ protected String tpid;
+
+ // TODO: Change sVlanId to Collection<VlanId>
+ private CarrierEthernetInni(ConnectPoint connectPoint, String uniCfgId,
+ Role role, VlanId sVlanId, String tpid,
+ Bandwidth usedCapacity,
+ Annotations...annotations) {
+
+ super(connectPoint, Type.INNI, uniCfgId, annotations);
+
+ // TODO: Check for null
+ this.role = role;
+ this.sVlanIdSet = Sets.newConcurrentHashSet();
+ // The following applies only to service-specific INNIs
+ if (sVlanId != null) {
+ this.sVlanIdSet.add(sVlanId);
+ // TODO: Use role correctly
+ this.role = Role.HUB;
+ this.usedCapacity = usedCapacity;
+ this.tpid = tpid;
+ }
+ }
+
+ /**
+ * Adds the resources associated with an FC-specific INNI to a global INNI.
+ *
+ * @param inni the FC-specific INNI to be added
+ */
+ @Override
+ public void addEcNi(CarrierEthernetNetworkInterface inni) {
+ // Add S-VLAN ID
+ if (inni.sVlanId() != VlanId.NONE) {
+ this.sVlanIdSet.add(inni.sVlanId());
+ }
+ // Used capacity cannot be more than INNI capacity
+ this.usedCapacity = Bandwidth.bps(Math.min(this.usedCapacity.bps() + inni.usedCapacity().bps(),
+ this.capacity.bps()));
+ }
+
+ /**
+ * Removes the resources associated with an FC-specific INNI from a global INNI.
+ *
+ * @param inni the FC-specific INNI to be removed
+ */
+ @Override
+ public void removeEcNi(CarrierEthernetNetworkInterface inni) {
+ // Remove UNI CE-VLAN ID
+ sVlanIdSet.remove(inni.sVlanId());
+ // Redundant check - should be avoided by check in validateBwp
+ this.usedCapacity = Bandwidth.bps(Math.max(this.usedCapacity.bps() - inni.usedCapacity().bps(), 0));
+ }
+
+ /**
+ * Validates whether an FC-specific INNI is compatible with the corresponding global INNI.
+ *
+ * @param inni the FC-specific INNI
+ * @return boolean value indicating whether the INNIs are compatible
+ */
+ @Override
+ public boolean validateEcNi(CarrierEthernetNetworkInterface inni) {
+
+ // Check if the S-VLAN ID of the INNI is already included in global INNI
+ if (inni.sVlanId() != null) {
+ if (sVlanIdSet.contains(inni.sVlanId())) {
+ log.error("S-VLAN ID {} already exists in INNI {}", inni.sVlanId().toString(), this.id());
+ return false;
+ }
+ }
+
+ // Check whether there are enough available resources on the INNI
+ if (usedCapacity.bps() + inni.usedCapacity().bps() > capacity.bps()) {
+ log.error("INNI {} cannot be added to global INNI {} due to lack of resources", inni.id(), this.id());
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Returns INNI role - applicable only to service-specific INNIs.
+ *
+ * @return INNI role
+ */
+ @Override
+ public Role role() {
+ return role;
+ }
+
+ /**
+ * Returns the S-VLAN id associated with a service INNI, or the first S-VLAN ID found for a global INNI.
+ * This is assumed to be the S-TAG of another FC interconnected with this INNI.
+ *
+ * @return S-VLAN id
+ */
+ @Override
+ public VlanId sVlanId() {
+ if (sVlanIdSet.isEmpty()) {
+ return VlanId.NONE;
+ } else {
+ return sVlanIdSet.iterator().next();
+ }
+ }
+
+ /**
+ * Always returns null, since CE-VLAN IDs are not associated with INNIs.
+ *
+ * @return null
+ */
+ @Override
+ public VlanId ceVlanId() {
+ return null;
+ }
+
+ /**
+ * Returns the set of S-VLAN ids associated with the INNI.
+ * Those are assumed to be the S-TAGs of other FCs interconnected with this INNI.
+ *
+ * @return S-VLAN id set
+ */
+ public Set<VlanId> sVlanIdSet() {
+ return ImmutableSet.copyOf(sVlanIdSet);
+ }
+
+ // FIXME: Find a better way to implement this method
+ /**
+ * Sets the S-VLAN id associated with an FC INNI.
+ *
+ * @param sVlanId S-VLAN id to set
+ */
+ public void setSVlanId(VlanId sVlanId) {
+ sVlanIdSet.add(sVlanId);
+ }
+
+ /**
+ * Returns INNI tpid - applicable only to service-specific INNIs.
+ *
+ * @return tpid
+ */
+ public String tpid() {
+ return tpid;
+ }
+
+ @Override
+ public String toString() {
+
+ return toStringHelper(this)
+ .add("id", this.id)
+ .add("cfgId", this.cfgId)
+ .add("role", role)
+ .add("refCount", refCount)
+ .add("sVlanIds", sVlanIdSet)
+ .add("capacity", this.capacity)
+ .add("usedCapacity", this.usedCapacity).toString();
+ }
+
+ /**
+ * Returns a new builder.
+ *
+ * @return new builder
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ /**
+ * Builder of CarrierEthernetInni entities.
+ */
+ public static final class Builder {
+
+ private ConnectPoint cp;
+ private String cfgId;
+ private Role role;
+ private VlanId sVlanId;
+ private String tpid;
+ private Bandwidth usedCapacity;
+ private Annotations annotations;
+
+ /**
+ * Sets the cp of this builder.
+ *
+ * @param cp the builder cp to set
+ * @return this builder instance
+ */
+ public Builder cp(ConnectPoint cp) {
+ this.cp = cp;
+ return this;
+ }
+
+ /**
+ * Sets the cfgId of this builder.
+ *
+ * @param cfgId the builder cfgId to set
+ * @return this builder instance
+ */
+ public Builder cfgId(String cfgId) {
+ this.cfgId = cfgId;
+ return this;
+ }
+
+ /**
+ * Sets the role of this builder.
+ *
+ * @param role the builder role to set
+ * @return this builder instance
+ */
+ public Builder role(Role role) {
+ this.role = role;
+ return this;
+ }
+
+ /**
+ * Sets the sVlanId of this builder.
+ *
+ * @param sVlanId the builder sVlanId to set
+ * @return this builder instance
+ */
+ public Builder sVlanId(VlanId sVlanId) {
+ this.sVlanId = sVlanId;
+ return this;
+ }
+
+ /**
+ * Sets the tpid of this builder.
+ *
+ * @param tpid the builder tpid to set
+ * @return this builder instance
+ */
+ public Builder tpid(String tpid) {
+ this.tpid = tpid;
+ return this;
+ }
+
+ /**
+ * Sets the usedCapacity of this builder.
+ *
+ * @param usedCapacity the builder usedCapacity to set
+ * @return this builder instance
+ */
+ public Builder usedCapacity(Bandwidth usedCapacity) {
+ this.usedCapacity = usedCapacity;
+ return this;
+ }
+
+ /**
+ * Sets annotations.
+ *
+ * @param annotations annotations
+ * @return this builder instance
+ */
+ public CarrierEthernetInni.Builder annotations(Annotations annotations) {
+ this.annotations = annotations;
+ return this;
+ }
+
+ /**
+ * Builds a new CarrierEthernetInni instance.
+ * based on this builder's parameters
+ *
+ * @return a new CarrierEthernetInni instance
+ */
+ public CarrierEthernetInni build() {
+ return new CarrierEthernetInni(cp, cfgId, role, sVlanId, tpid, usedCapacity, annotations);
+ }
+ }
+}
+
diff --git a/ce-api/src/main/java/org/opencord/ce/api/models/CarrierEthernetLogicalTerminationPoint.java b/ce-api/src/main/java/org/opencord/ce/api/models/CarrierEthernetLogicalTerminationPoint.java
new file mode 100644
index 0000000..3e0e582
--- /dev/null
+++ b/ce-api/src/main/java/org/opencord/ce/api/models/CarrierEthernetLogicalTerminationPoint.java
@@ -0,0 +1,209 @@
+/*
+ * Copyright 2017-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.opencord.ce.api.models;
+
+
+import org.onosproject.net.ConnectPoint;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Representation of a CE Logical Termination Point.
+ */
+public class CarrierEthernetLogicalTerminationPoint {
+
+ public enum Role {
+
+ WORKING("Working"),
+ PROTECTION("Protection"),
+ PROTECTED("Protected"),
+ SYMMETRIC("Symmetric"),
+ HUB("Hub"),
+ SPOKE("Spoke"),
+ LEAF("Leaf"),
+ // FIXME: Remove that after hackathon?
+ TRUNK("Trunk"),
+ ROOT("Root");
+
+ private String value;
+
+ Role(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public String toString() {
+ return value;
+ }
+ }
+
+ protected String ltpId;
+ protected String ltpCfgId;
+ protected Role role;
+ // A global LTP will point to the corresponding global NI and a service LTP to the corresponding service NI
+ protected CarrierEthernetNetworkInterface ni;
+
+ public CarrierEthernetLogicalTerminationPoint(String ltpCfgId, CarrierEthernetNetworkInterface ni) {
+ checkNotNull(ni);
+ this.ni = ni;
+ // NOTE: Role is expected to be null for global LTPs/NIs
+ if (ni.type().equals(CarrierEthernetNetworkInterface.Type.UNI)) {
+ this.role = (ni.role() == null ? null : Role.valueOf(((CarrierEthernetUni) ni).role().name()));
+ } else if (ni.type().equals(CarrierEthernetNetworkInterface.Type.INNI)) {
+ this.role = (ni.role() == null ? null : Role.valueOf(((CarrierEthernetInni) ni).role().name()));
+ } else if (ni.type().equals(CarrierEthernetNetworkInterface.Type.ENNI)) {
+ this.role = (ni.role() == null ? null : Role.valueOf(((CarrierEthernetEnni) ni).role().name()));
+ }
+ this.ltpId = this.cp().deviceId().toString() + "/" + this.cp().port().toString();
+ this.ltpCfgId = (ltpCfgId == null ? this.ltpId : ltpCfgId);
+ }
+
+ public CarrierEthernetLogicalTerminationPoint(ConnectPoint cp, String ltpCfgId,
+ CarrierEthernetNetworkInterface.Type niType,
+ CarrierEthernetLogicalTerminationPoint.Role role) {
+ this.ltpId = cp.deviceId().toString() + "/" + cp.port().toString();
+ this.ltpCfgId = (ltpCfgId == null ? this.ltpId : ltpCfgId);
+ this.role = role;
+ // NOTE: Role is expected to be null for global LTPs/NIs
+ // FIXME: Provide appropriate mapping between LTP and NI roles (e.g. ROOT -> HUB, LEAF -> SPOKE)
+ if (niType.equals(CarrierEthernetNetworkInterface.Type.UNI)) {
+ CarrierEthernetUni.Role uniRole = (role == null) ? null : CarrierEthernetUni.Role.valueOf(role.name());
+ this.ni = CarrierEthernetUni.builder()
+ .cp(cp)
+ .cfgId(ltpId)
+ .role(uniRole)
+ .build();
+ } else if (niType.equals(CarrierEthernetNetworkInterface.Type.INNI)) {
+ CarrierEthernetInni.Role inniRole = (role == null) ? null : CarrierEthernetInni.Role.valueOf(role.name());
+ this.ni = CarrierEthernetInni.builder()
+ .cp(cp)
+ .cfgId(ltpId)
+ .role(inniRole)
+ .build();
+ } else if (niType.equals(CarrierEthernetNetworkInterface.Type.ENNI)) {
+ CarrierEthernetEnni.Role enniRole = (role == null) ? null : CarrierEthernetEnni.Role.valueOf(role.name());
+ this.ni = CarrierEthernetEnni.builder()
+ .cp(cp)
+ .cfgId(ltpId)
+ .role(enniRole)
+ .build();
+ }
+ }
+
+ /**
+ * Returns associated connect point.
+ *
+ * @return associated connect point
+ */
+ public ConnectPoint cp() {
+ return ni.cp();
+ }
+
+ /**
+ * Returns LTP string identifier.
+ *
+ * @return LTP string identifier
+ */
+ public String id() {
+ return ltpId;
+ }
+
+ /**
+ * Returns LTP string config identifier.
+ *
+ * @return LTP string config identifier
+ */
+ public String cfgId() {
+ return ltpCfgId;
+ }
+
+ /**
+ * Returns LTP role - applicable only to service-specific LTPs.
+ *
+ * @return LTP role
+ */
+ public Role role() {
+ return role;
+ }
+
+ /**
+ * Returns LTP type.
+ *
+ * @return LTP type
+ */
+ public CarrierEthernetNetworkInterface.Type type() {
+ return ni.type();
+ }
+
+ /**
+ * Returns the NI associated with the LTP or null of there is none.
+ *
+ * @return NI associated with LTP
+ */
+ public CarrierEthernetNetworkInterface ni() {
+ return ni;
+ }
+
+ /**
+ * Returns the scope of the LTP (always matches that of the associated NI).
+ *
+ * @return LTP scope
+ */
+ public CarrierEthernetNetworkInterface.Scope scope() {
+ return this.ni().scope();
+ }
+
+ /**
+ * Returns counter with the number of references (from EVCs/FCs) to the associated NI.
+ *
+ * @return number of references counter
+ */
+ public AtomicInteger refCount() {
+ return ni().refCount();
+ }
+
+ /**
+ * Sets the NI associated with the LTP.
+ *
+ * @param ni the NI to set
+ */
+ public void setNi(CarrierEthernetNetworkInterface ni) {
+ this.ni = ni;
+ }
+
+ /**
+ * Sets LTP role - applicable only to EVC- or FC-specific LTPs.
+ *
+ * @param role the LTP role to set
+ */
+ public void setRole(Role role) {
+ this.role = role;
+ }
+
+ public String toString() {
+
+ return toStringHelper(this)
+ .add("id", ltpId)
+ .add("cfgId", ltpCfgId)
+ .add("role", role)
+ .add("ni", ni).toString();
+ }
+
+}
diff --git a/ce-api/src/main/java/org/opencord/ce/api/models/CarrierEthernetNetworkInterface.java b/ce-api/src/main/java/org/opencord/ce/api/models/CarrierEthernetNetworkInterface.java
new file mode 100644
index 0000000..322e3a4
--- /dev/null
+++ b/ce-api/src/main/java/org/opencord/ce/api/models/CarrierEthernetNetworkInterface.java
@@ -0,0 +1,253 @@
+/*
+ * Copyright 2017-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.opencord.ce.api.models;
+
+
+import com.google.common.base.Objects;
+import org.onlab.osgi.DefaultServiceDirectory;
+import org.onlab.osgi.ServiceDirectory;
+import org.onlab.packet.VlanId;
+import org.onlab.util.Bandwidth;
+import org.onosproject.net.AbstractAnnotated;
+import org.onosproject.net.Annotations;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.Port;
+import org.onosproject.net.device.DeviceService;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Representation of a Carrier Ethernet Network Interface (UNI, INNI or ENNI).
+ */
+public abstract class CarrierEthernetNetworkInterface extends AbstractAnnotated {
+
+ protected static ServiceDirectory serviceDirectory = new DefaultServiceDirectory();
+
+ public enum Scope {
+ GLOBAL, SERVICE
+ }
+
+ public enum Type {
+ UNI, INNI, ENNI, GENERIC
+ }
+
+ protected ConnectPoint connectPoint;
+ protected String id;
+ protected String cfgId;
+ protected Bandwidth capacity;
+ protected Bandwidth usedCapacity;
+ protected Scope scope;
+ protected AtomicInteger refCount;
+ protected Type type;
+
+
+ public CarrierEthernetNetworkInterface(ConnectPoint connectPoint, Type type, String cfgId,
+ Annotations...annotations) {
+ super(annotations);
+ checkNotNull(connectPoint);
+ checkNotNull(type);
+ this.type = type;
+ this.connectPoint = connectPoint;
+ this.id = this.connectPoint.deviceId().toString() + "/" + this.connectPoint.port().toString();
+ this.cfgId = (cfgId == null ? this.id : cfgId);
+ DeviceService deviceService = serviceDirectory.get(DeviceService.class);
+ Port port = deviceService.getPort(connectPoint.deviceId(), connectPoint.port());
+ if (port != null) {
+ this.capacity = Bandwidth.mbps(port.portSpeed());
+ } else {
+ this.capacity = Bandwidth.mbps((double) 1000);
+ }
+
+ this.usedCapacity = Bandwidth.mbps((double) 0);
+ this.scope = null;
+ this.refCount = new AtomicInteger();
+ }
+
+ /**
+ * Returns associated connect point.
+ *
+ * @return associated connect point
+ */
+ public ConnectPoint cp() {
+ return connectPoint;
+ }
+
+ /**
+ * Returns NI string identifier.
+ *
+ * @return NI string identifier
+ */
+ public String id() {
+ return id;
+ }
+
+ /**
+ * Returns NI string config identifier.
+ *
+ * @return NI string config identifier
+ */
+ public String cfgId() {
+ return cfgId;
+ }
+
+ /**
+ * Returns NI capacity.
+ *
+ * @return NI capacity
+ */
+ public Bandwidth capacity() {
+ return capacity;
+ }
+
+ /**
+ * Returns NI used capacity.
+ *
+ * @return NI used capacity
+ */
+ public Bandwidth usedCapacity() {
+ return usedCapacity;
+ }
+
+ /**
+ * Returns the NI S-TAG.
+ *
+ * @return NI S-TAG
+ */
+ public abstract VlanId sVlanId();
+
+ /**
+ * Returns the NI CE-VLAN ID.
+ *
+ * @return NI CE-VLAN ID
+ */
+ public abstract VlanId ceVlanId();
+
+ /**
+ * Returns the scope of the NI (GLOBAL or SERVICE).
+ *
+ * @return NI scope
+ */
+ public Scope scope() {
+ return scope;
+ }
+
+ /**
+ * Returns the type of the NI (UNI, INNI or ENNI).
+ *
+ * @return NI scope
+ */
+ public Type type() {
+ return type;
+ }
+
+ /**
+ * Returns counter with the number of references (from EVCs/FCs) to the particular NI.
+ *
+ * @return number of references counter
+ */
+ public AtomicInteger refCount() {
+ return refCount;
+ }
+
+ /**
+ * Sets NI string identifier.
+ *
+ * @param id the UNI string identifier to set
+ */
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ /**
+ * Sets NI string config identifier.
+ *
+ * @param cfgId the UNI string config identifier to set
+ */
+ public void setCfgId(String cfgId) {
+ this.cfgId = cfgId;
+ }
+
+ /**
+ * Sets NI capacity.
+ *
+ * @param capacity the capacity to set
+ */
+ public void setCapacity(Bandwidth capacity) {
+ this.capacity = capacity;
+ }
+
+ /**
+ * Returns the NI role, depending on the NI.
+ *
+ * @param <T> the NI role
+ * @return the NI role
+ */
+ public abstract <T> T role();
+
+ /**
+ * Adds the resources associated with an EVC- or FC-specific NI to a global NI.
+ *
+ * @param ni the EVC- or FC-specific NI to be added
+ */
+ public abstract void addEcNi(CarrierEthernetNetworkInterface ni);
+
+ /**
+ * Removes the resources associated with an EVC- or FC-specific NI from a global NI.
+ *
+ * @param ni the EVC- or FC-specific NI to be removed
+ */
+ public abstract void removeEcNi(CarrierEthernetNetworkInterface ni);
+
+ /**
+ * Validates whether an EVC- or FC-specific NI is compatible with the corresponding global NI.
+ *
+ * @param ni the EVC- or FC-specific NI
+ * @return boolean value indicating whether the NIs are compatible
+ */
+ public abstract boolean validateEcNi(CarrierEthernetNetworkInterface ni);
+
+ @Override
+ public String toString() {
+
+ return toStringHelper(this)
+ .add("id", id)
+ .add("cfgId", cfgId)
+ .add("capacity", capacity)
+ .add("usedCapacity", usedCapacity).toString();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ CarrierEthernetNetworkInterface that = (CarrierEthernetNetworkInterface) o;
+ return Objects.equal(connectPoint, that.connectPoint);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(connectPoint);
+ }
+
+}
diff --git a/ce-api/src/main/java/org/opencord/ce/api/models/CarrierEthernetSpanningTreeWeight.java b/ce-api/src/main/java/org/opencord/ce/api/models/CarrierEthernetSpanningTreeWeight.java
new file mode 100644
index 0000000..5f480d6
--- /dev/null
+++ b/ce-api/src/main/java/org/opencord/ce/api/models/CarrierEthernetSpanningTreeWeight.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2017-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.opencord.ce.api.models;
+
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.topology.LinkWeight;
+import org.onosproject.net.topology.TopologyEdge;
+import org.onosproject.net.topology.TopologyService;
+import org.slf4j.Logger;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Weight class to cause path selection only on the pre-calculated spanning tree.
+ */
+public class CarrierEthernetSpanningTreeWeight implements LinkWeight {
+
+ private final Logger log = getLogger(getClass());
+
+ protected TopologyService topologyService = null;
+
+ public CarrierEthernetSpanningTreeWeight(TopologyService topologyService) {
+ this.topologyService = topologyService;
+ }
+
+ @Override
+ public double weight(TopologyEdge edge) {
+ if (!isBroadCastPoint(edge.link().src()) || !isBroadCastPoint(edge.link().dst())) {
+ return -1;
+ } else {
+ return 1;
+ }
+ }
+
+ /**
+ * Checks if a connect point is on the pre-calculated spanning tree.
+ *
+ * @param cp the connect point to check
+ * @return true if the connect point is on the spanning tree and false otherwise
+ */
+ private boolean isBroadCastPoint(ConnectPoint cp) {
+ // TODO: Get topology snapshot so that same spanning tree is used by all pairs if topology changes
+ if (cp == null) {
+ log.info("Cp is null!");
+ }
+ if (topologyService == null) {
+ log.info("topologyservice is null!");
+ }
+ return topologyService.isBroadcastPoint(topologyService.currentTopology(), cp);
+ }
+}
diff --git a/ce-api/src/main/java/org/opencord/ce/api/models/CarrierEthernetUni.java b/ce-api/src/main/java/org/opencord/ce/api/models/CarrierEthernetUni.java
new file mode 100644
index 0000000..2e97c61
--- /dev/null
+++ b/ce-api/src/main/java/org/opencord/ce/api/models/CarrierEthernetUni.java
@@ -0,0 +1,419 @@
+/*
+ * Copyright 2017-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.opencord.ce.api.models;
+
+
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Sets;
+import org.onlab.packet.VlanId;
+import org.onlab.util.Bandwidth;
+import org.onosproject.net.Annotations;
+import org.onosproject.net.ConnectPoint;
+import org.slf4j.Logger;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Representation of a Carrier Ethernet UNI.
+ * Class can be used in different two ways:
+ * 1. As a global UNI descriptor containing one or more BW profiles
+ * 2. As a service-specific UNI descriptor containing a single BW profile and including a type (root, leaf)
+ */
+public final class CarrierEthernetUni extends CarrierEthernetNetworkInterface {
+
+ private final Logger log = getLogger(getClass());
+
+ public enum Role {
+
+ ROOT("Root"),
+ LEAF("Leaf");
+
+ private String value;
+
+ Role(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public String toString() {
+ return value;
+ }
+ }
+
+ protected Role role = null;
+ protected Set<VlanId> ceVlanIdSet = Sets.newConcurrentHashSet();
+
+ // Note: INTERFACE BWP map can only have up to one element
+ protected final Map<CarrierEthernetBandwidthProfile.Type, Map<String, CarrierEthernetBandwidthProfile>> bwpMap =
+ new HashMap<>();
+
+ // TODO: May be needed to add refCount for CoS BWPs - only applicable to global UNIs
+ // TODO: Change ceVlanId to Collection<VlanId>
+ private CarrierEthernetUni(ConnectPoint cp, String uniCfgId, Role role,
+ VlanId ceVlanId,
+ CarrierEthernetBandwidthProfile bwp,
+ Annotations annotations) {
+ super(cp, Type.UNI, uniCfgId, annotations);
+
+ this.role = role;
+ // FIXME: Set the NI scope directly instead?
+ this.scope = (role == null ? Scope.GLOBAL : Scope.SERVICE);
+ if (ceVlanId != null) {
+ this.ceVlanIdSet.add(ceVlanId);
+ }
+ for (CarrierEthernetBandwidthProfile.Type bwpType : CarrierEthernetBandwidthProfile.Type.values()) {
+ this.bwpMap.put(bwpType, new HashMap<>());
+ }
+
+ if (bwp != null) {
+ // Limit the CIR of the provided bwp according to UNI capacity
+ if (bwp.cir().bps() > this.capacity.bps()) {
+ log.warn("UNI {}: Limiting provided CIR ({} bps) to UNI capacity ({} bps)",
+ this.id, (long) bwp.cir().bps(), this.capacity);
+ }
+ bwp.setCir(Bandwidth.bps(Math.min(bwp.cir().bps(), this.capacity.bps())));
+
+ // Limit the EIR of the provided bwp according to the UNI capacity minus CIR
+ if (bwp.eir().bps() > this.capacity.bps() - bwp.cir().bps()) {
+ log.warn("UNI {}: Limiting provided EIR ({} bps) to UNI capacity minus CIR ({} bps)",
+ this.id, bwp.eir().bps(), this.capacity.bps() - bwp.cir().bps());
+ }
+ bwp.setEir(Bandwidth.bps(Math.min(bwp.eir().bps(), this.capacity.bps() - bwp.cir().bps())));
+
+ addBandwidthProfile(bwp);
+ }
+ }
+
+ /**
+ * Adds a BW profile to a UNI.
+ *
+ * @param bwp the BWP to be added
+ */
+ public void addBandwidthProfile(CarrierEthernetBandwidthProfile bwp) {
+
+ Map<String, CarrierEthernetBandwidthProfile> subBwpMap = this.bwpMap.get(bwp.type());
+ subBwpMap.put(bwp.id(), bwp);
+ this.bwpMap.put(bwp.type(), subBwpMap);
+ // Used capacity cannot be more than UNI capacity (redundant check - should be avoided by check in validateBwp)
+ this.usedCapacity = Bandwidth.bps(Math.min(this.usedCapacity.bps() + bwp.cir().bps(), this.capacity.bps()));
+ }
+
+ /**
+ * Adds the resources associated with an EVC- or FC-specific UNI to a global UNI.
+ *
+ * @param ni the EVC- or FC-specific UNI to be added
+ */
+ @Override
+ public void addEcNi(CarrierEthernetNetworkInterface ni) {
+ CarrierEthernetUni uni;
+ if (!(ni instanceof CarrierEthernetUni)) {
+ return;
+ } else {
+ uni = (CarrierEthernetUni) ni;
+ }
+
+ // Add CE-VLAN ID
+ if (uni.ceVlanId() != VlanId.NONE) {
+ this.ceVlanIdSet.add(uni.ceVlanId());
+ }
+
+ // Add UNI BWP
+ CarrierEthernetBandwidthProfile bwp = uni.bwp();
+ if (bwp != null) {
+ Map<String, CarrierEthernetBandwidthProfile> subBwpMap = this.bwpMap.get(bwp.type());
+ subBwpMap.put(bwp.id(), bwp);
+ this.bwpMap.put(bwp.type(), subBwpMap);
+ // Used capacity cannot be more than UNI capacity
+ // (redundant check - should be avoided by check in validateBwp)
+ this.usedCapacity = Bandwidth.bps(Math.min(this.usedCapacity.bps() + bwp.cir().bps(), this.capacity.bps()));
+ }
+ }
+
+ /**
+ * Removes the resources associated with an EVC- or FC-specific UNI from a global UNI.
+ *
+ * @param ni the EVC- or FC-specific UNI to be removed
+ */
+ @Override
+ public void removeEcNi(CarrierEthernetNetworkInterface ni) {
+ CarrierEthernetUni uni;
+ if (!(ni instanceof CarrierEthernetUni)) {
+ return;
+ } else {
+ uni = (CarrierEthernetUni) ni;
+ }
+
+ // Remove UNI CE-VLAN ID
+ if (uni.ceVlanId() != VlanId.NONE) {
+ ceVlanIdSet.remove(uni.ceVlanId());
+ }
+
+ // Remove UNI BWP
+ CarrierEthernetBandwidthProfile bwp = uni.bwp();
+ Map<String, CarrierEthernetBandwidthProfile> subBwpMap = this.bwpMap.get(bwp.type());
+ subBwpMap.remove(bwp.id());
+ this.bwpMap.put(bwp.type(), subBwpMap);
+ // Redundant check - should be avoided by check in validateBwp
+ this.usedCapacity = Bandwidth.bps(Math.max(this.usedCapacity.bps() - bwp.cir().bps(), 0));
+ }
+
+ /**
+ * Validates whether an EVC- or FC-specific UNI is compatible with the corresponding global UNI.
+ *
+ * @param ni the EVC- or FC-specific UNI
+ * @return boolean value indicating whether the UNIs are compatible
+ */
+ @Override
+ public boolean validateEcNi(CarrierEthernetNetworkInterface ni) {
+ CarrierEthernetUni uni;
+ if (!(ni instanceof CarrierEthernetUni)) {
+ return false;
+ } else {
+ uni = (CarrierEthernetUni) ni;
+ }
+
+ // Check if the CE-VLAN ID of the UNI is already included in global UNI
+ if (uni.ceVlanId() != VlanId.NONE) {
+ if (ceVlanIdSet.contains(uni.ceVlanId())) {
+ log.error("CE-VLAN ID {} already exists in UNI {}", uni.ceVlanId().toString(), this.id());
+ return false;
+ }
+ }
+
+ CarrierEthernetBandwidthProfile bwp = uni.bwp();
+
+ // Check if the UNI BW profile is allowed based on its type and id and the existing profiles on the global UNI
+ for (CarrierEthernetBandwidthProfile.Type bwpType : CarrierEthernetBandwidthProfile.Type.values()) {
+ Map<String, CarrierEthernetBandwidthProfile> subBwpMap = this.bwpMap.get(bwpType);
+ if (!(subBwpMap.isEmpty())) {
+ if (bwpType != bwp.type()) {
+ log.error("Different bandwidth profile type than {} already exists in UNI {}",
+ bwp.type().name(), this.id());
+ return false;
+ } else if (subBwpMap.containsKey(bwp.id())) {
+ log.error("Bandwidth profile {} already exists in UNI {}", bwp.id(), this.id());
+ return false;
+ } else if (bwp.type().equals(CarrierEthernetBandwidthProfile.Type.INTERFACE)) {
+ log.error("Another bandwidth profile already exists in UNI {}", this.id());
+ return false;
+ }
+ }
+ }
+
+ // Check whether there are enough available resources on the UNI
+ if (usedCapacity.bps() + bwp.cir().bps() > capacity.bps()) {
+ log.error("Bandwidth profile {} cannot be added to UNI {} due to lack of resources", bwp.id(), this.id());
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Returns UNI role (ROOT or LEAF) - applicable only to service-specific UNIs.
+ *
+ * @return UNI role
+ */
+ @Override
+ public Role role() {
+ return role;
+ }
+
+ /**
+ * Returns the CE-VLAN id associated with a local UNI, or the first CE-VLAN ID found for a global UNI.
+ *
+ * @return CE-VLAN id
+ */
+ @Override
+ public VlanId ceVlanId() {
+ if (ceVlanIdSet.isEmpty()) {
+ return VlanId.NONE;
+ } else {
+ return ceVlanIdSet.iterator().next();
+ }
+ }
+
+ /**
+ * Always returns null, since S-TAGs are not associated with UNIs.
+ *
+ * @return null
+ */
+ @Override
+ public VlanId sVlanId() {
+ return null;
+ }
+
+ /**
+ * Returns the set of CE-VLAN ids associated with the UNI.
+ *
+ * @return CE-VLAN id set
+ */
+ public Set<VlanId> ceVlanIdSet() {
+ return ImmutableSet.copyOf(ceVlanIdSet);
+ }
+
+ /**
+ * Returns the first non-null BWP of the UNI found - used mainly for service-specific UNIs.
+ * Note: The EVC-specific UNI representation will only have one BWP
+ *
+ * @return first non-null BWP of the UNI
+ */
+ public CarrierEthernetBandwidthProfile bwp() {
+
+ for (CarrierEthernetBandwidthProfile.Type bwpType : CarrierEthernetBandwidthProfile.Type.values()) {
+ if (!(this.bwpMap.get(bwpType).isEmpty())) {
+ return bwpMap.get(bwpType).entrySet().iterator().next().getValue();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns a collection of all BWPs of the UNI.
+ *
+ * @return all BWPs of the UNI
+ */
+ public Collection<CarrierEthernetBandwidthProfile> bwps() {
+
+ for (CarrierEthernetBandwidthProfile.Type bwpType : CarrierEthernetBandwidthProfile.Type.values()) {
+ if (!(this.bwpMap.get(bwpType).isEmpty())) {
+ return bwpMap.get(bwpType).values();
+ }
+ }
+ // Return an empty collection if no BWPs exist
+ return Collections.emptyList();
+ }
+
+ @Override
+ public String toString() {
+
+ return toStringHelper(this)
+ .add("id", this.id)
+ .add("cfgId", this.cfgId)
+ .add("role", role)
+ .add("refCount", refCount)
+ .add("ceVlanIds", ceVlanIdSet)
+ .add("capacity", this.capacity)
+ .add("usedCapacity", this.usedCapacity)
+ .add("bandwidthProfiles", this.bwps()).toString();
+ }
+
+ /**
+ * Returns a new builder.
+ *
+ * @return new builder
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ /**
+ * Builder of CarrierEthernetUni entities.
+ */
+ public static final class Builder {
+
+ private ConnectPoint cp;
+ private String cfgId;
+ private Role role;
+ private VlanId ceVlanId;
+ private CarrierEthernetBandwidthProfile bwp;
+ private Annotations annotations;
+
+ /**
+ * Sets the cp of this builder.
+ *
+ * @param cp the builder cp to set
+ * @return this builder instance
+ */
+ public Builder cp(ConnectPoint cp) {
+ this.cp = cp;
+ return this;
+ }
+
+ /**
+ * Sets the cfgId of this builder.
+ *
+ * @param cfgId the builder cfgId to set
+ * @return this builder instance
+ */
+ public Builder cfgId(String cfgId) {
+ this.cfgId = cfgId;
+ return this;
+ }
+
+ /**
+ * Sets the role of this builder.
+ *
+ * @param role the builder role to set
+ * @return this builder instance
+ */
+ public Builder role(Role role) {
+ this.role = role;
+ return this;
+ }
+
+ /**
+ * Sets the ceVlanId of this builder.
+ *
+ * @param ceVlanId the builder ceVlanId to set
+ * @return this builder instance
+ */
+ public Builder ceVlanId(VlanId ceVlanId) {
+ this.ceVlanId = ceVlanId;
+ return this;
+ }
+
+ /**
+ * Sets the bwp of this builder.
+ *
+ * @param bwp the builder bwp to set
+ * @return this builder instance
+ */
+ public Builder bwp(CarrierEthernetBandwidthProfile bwp) {
+ this.bwp = bwp;
+ return this;
+ }
+ /**
+ * Sets annotations.
+ *
+ * @param annotations annotations
+ * @return this builder instance
+ */
+ public CarrierEthernetUni.Builder annotations(Annotations annotations) {
+ this.annotations = annotations;
+ return this;
+ }
+
+ /**
+ * Builds a new CarrierEthernetUni instance.
+ * based on this builder's parameters
+ *
+ * @return a new CarrierEthernetUni instance
+ */
+ public CarrierEthernetUni build() {
+ return new CarrierEthernetUni(cp, cfgId, role, ceVlanId, bwp, annotations);
+ }
+ }
+}
+
diff --git a/ce-api/src/main/java/org/opencord/ce/api/models/CarrierEthernetVirtualConnection.java b/ce-api/src/main/java/org/opencord/ce/api/models/CarrierEthernetVirtualConnection.java
new file mode 100644
index 0000000..15686d9
--- /dev/null
+++ b/ce-api/src/main/java/org/opencord/ce/api/models/CarrierEthernetVirtualConnection.java
@@ -0,0 +1,250 @@
+/*
+ * Copyright 2017-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.opencord.ce.api.models;
+
+import com.google.common.collect.ImmutableSet;
+
+import java.time.Duration;
+import java.util.HashSet;
+import java.util.Set;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Representation of a Carrier Ethernet EVC.
+ */
+public final class CarrierEthernetVirtualConnection extends CarrierEthernetConnection {
+
+ private Short shortId;
+ private Set<CarrierEthernetUni> uniSet;
+ private boolean isVirtual;
+ private Integer maxNumUni;
+ private Set<CarrierEthernetForwardingConstruct> fcSet;
+
+ // Maximum possible number of UNIs for non-Point-to-Point EVCs
+ public static final Integer MAX_NUM_UNI = 1000;
+
+ // TODO: Remove id from constructor - currently used only when updating EVC
+ private CarrierEthernetVirtualConnection(EvcConnId id, String cfgId, Type type,
+ Integer maxNumUni,
+ Set<CarrierEthernetUni> uniSet,
+ Duration maxLatency) {
+ super(id, cfgId, type, maxLatency);
+ this.maxNumUni = maxNumUni != null ? maxNumUni :
+ type.equals(Type.POINT_TO_POINT) ? 2 : MAX_NUM_UNI;
+ this.uniSet = new HashSet<>(uniSet);
+ this.fcSet = new HashSet<>();
+ this.shortId = null;
+ }
+
+ /**
+ * Returns numerical identifier.
+ *
+ * @return numerical identifier
+ */
+ public Short shortId() {
+ return shortId;
+ }
+
+ /**
+ * Returns the Virtual status of the service (i.e. if all UNIs have CE-VLAN ids).
+ *
+ * @return true if service is virtual, false otherwise
+ */
+ public boolean isVirtual() {
+ return isVirtual;
+ }
+
+ /**
+ * Returns the maximum number of UNIs in the EVC.
+ *
+ * @return true the maximum number of UNIs in the EVC
+ */
+ public Integer maxNumUni() {
+ return maxNumUni;
+ }
+
+ /**
+ * Returns set of UNIs.
+ *
+ * @return set of UNIs
+ */
+ public Set<CarrierEthernetUni> uniSet() {
+ return ImmutableSet.copyOf(uniSet);
+ }
+
+ /**
+ * Returns the set of FCs associated with the EVC.
+ *
+ * @return set of FCs associated with the EVC
+ */
+ public Set<CarrierEthernetForwardingConstruct> fcSet() {
+ return ImmutableSet.copyOf(fcSet);
+ }
+
+ /**
+ * Set numerical identifier.
+ *
+ * @param shortId the numerical identifier to set
+ */
+ public void setShortId(Short shortId) {
+ this.shortId = shortId;
+ }
+
+ /**
+ * Sets the set of UNIs.
+ *
+ * @param uniSet the set of UNIs to be set
+ */
+ public void setUniSet(Set<CarrierEthernetUni> uniSet) {
+ this.uniSet = uniSet;
+ }
+
+ /**
+ * Sets the set of FCs.
+ *
+ * @param fcSet the set of UNIs to be set
+ */
+ public void setFcSet(Set<CarrierEthernetForwardingConstruct> fcSet) {
+ this.fcSet = fcSet;
+ }
+
+ /**
+ * Sets the Virtual status of the service.
+ *
+ * @param isVirtual boolean value with the status to set
+ */
+ public void setIsVirtual(boolean isVirtual) {
+ this.isVirtual = isVirtual;
+ }
+
+ @Override
+ public String toString() {
+
+ return toStringHelper(this)
+ .omitNullValues()
+ .add("id", id)
+ .add("cfgId", cfgId)
+ .add("type", type)
+ .add("state", state)
+ .add("UNIs", uniSet)
+ .add("FCs", fcSet).toString();
+ }
+
+ /**
+ * Returns a new builder.
+ *
+ * @return new builder
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ /**
+ * Builder of CarrierEthernetVirtualConnection entities.
+ */
+ public static final class Builder {
+
+ private EvcConnId id;
+ private String cfgId;
+ private Type type;
+ private Duration maxLatency;
+ private Set<CarrierEthernetUni> uniSet;
+ private Integer maxNumUni;
+
+ /**
+ * Sets the id of this builder.
+ *
+ * @param id the builder id to set
+ * @return this builder instance
+ */
+ public Builder id(EvcConnId id) {
+ this.id = id;
+ return this;
+ }
+
+ /**
+ * Sets the cfgId of this builder.
+ *
+ * @param cfgId the builder cfgId to set
+ * @return this builder instance
+ */
+ public Builder cfgId(String cfgId) {
+ this.cfgId = cfgId;
+ return this;
+ }
+
+ /**
+ * Sets the type of this builder.
+ *
+ * @param type the builder type to set
+ * @return this builder instance
+ */
+ public Builder type(Type type) {
+ this.type = type;
+ return this;
+ }
+
+ /**
+ * Sets the maxLatency of this builder.
+ *
+ * @param maxLatency the builder maxLatency to set
+ * @return this builder instance
+ */
+ public Builder maxLatency(Duration maxLatency) {
+ this.maxLatency = maxLatency;
+ return this;
+ }
+
+ /**
+ * Sets the uniSet of this builder.
+ *
+ * @param uniSet the builder uniSet to set
+ * @return this builder instance
+ */
+ public Builder uniSet(Set<CarrierEthernetUni> uniSet) {
+ this.uniSet = uniSet;
+ return this;
+ }
+
+ /**
+ * Sets the maxNumUni of this builder.
+ *
+ * @param maxNumUni the builder maxNumUni to set
+ * @return this builder instance
+ */
+ public Builder maxNumUni(Integer maxNumUni) {
+ this.maxNumUni = maxNumUni;
+ return this;
+ }
+
+ /**
+ * Builds a new CarrierEthernetVirtualConnection instance.
+ * based on this builder's parameters
+ *
+ * @return a new CarrierEthernetVirtualConnection instance
+ */
+ public CarrierEthernetVirtualConnection build() {
+ checkNotNull(type, "EVC must have a type");
+ checkArgument(uniSet != null && uniSet.size() > 1,
+ "EVC must include at least two UNIs");
+ return new CarrierEthernetVirtualConnection(id, cfgId, type, maxNumUni, uniSet, maxLatency);
+ }
+ }
+}
\ No newline at end of file
diff --git a/ce-api/src/main/java/org/opencord/ce/api/models/DomainEndPoint.java b/ce-api/src/main/java/org/opencord/ce/api/models/DomainEndPoint.java
new file mode 100644
index 0000000..f7d8375
--- /dev/null
+++ b/ce-api/src/main/java/org/opencord/ce/api/models/DomainEndPoint.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2017-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.opencord.ce.api.models;
+
+import org.onlab.packet.IpAddress;
+import org.onosproject.net.domain.DomainId;
+
+/**
+ * ONOS cluster endpoint for the communication between local and global.
+ */
+public class DomainEndPoint {
+ private DomainId domainId;
+ private IpAddress publicIp;
+ private int port;
+ private String username;
+ private String password;
+ private String topic;
+
+ public DomainEndPoint(DomainId domainId, IpAddress publicIp, int port,
+ String username, String password, String topic) {
+ this.domainId = domainId;
+ this.publicIp = publicIp;
+ this.port = port;
+ this.username = username;
+ this.password = password;
+ this.topic = topic;
+ }
+
+ public DomainId domainId() {
+ return domainId;
+ }
+
+ public IpAddress publicIp() {
+ return publicIp;
+ }
+
+ public int port() {
+ return port;
+ }
+
+ public String username() {
+ return username;
+ }
+
+ public String password() {
+ return password;
+ }
+
+ public String topic() {
+ return topic;
+ }
+}
diff --git a/ce-api/src/main/java/org/opencord/ce/api/models/EvcConnId.java b/ce-api/src/main/java/org/opencord/ce/api/models/EvcConnId.java
new file mode 100644
index 0000000..77de4a2
--- /dev/null
+++ b/ce-api/src/main/java/org/opencord/ce/api/models/EvcConnId.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2017-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.opencord.ce.api.models;
+
+import org.onlab.util.Identifier;
+
+/**
+ * Virtual connection identifier class.
+ */
+public class EvcConnId extends Identifier<String> {
+
+ public EvcConnId(String connId) {
+ super(connId);
+ }
+
+ public static EvcConnId of(String connId) {
+ return new EvcConnId(connId);
+ }
+}
diff --git a/ce-api/src/main/java/org/opencord/ce/api/models/PortVlanConfig.java b/ce-api/src/main/java/org/opencord/ce/api/models/PortVlanConfig.java
new file mode 100644
index 0000000..be2e5ee
--- /dev/null
+++ b/ce-api/src/main/java/org/opencord/ce/api/models/PortVlanConfig.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2017-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.opencord.ce.api.models;
+
+import org.onlab.packet.VlanId;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.config.Config;
+
+import java.util.Optional;
+
+/**
+ * Configuration information for edge connect point and corresponding VLAN tag.
+ */
+public class PortVlanConfig extends Config<ConnectPoint> {
+ public static final String CONFIG_KEY = "portVlan";
+
+ public static final String S_TAG_KEY = "s-tag";
+
+ public Optional<VlanId> portVlanId() {
+ String s = get(S_TAG_KEY, null);
+ if (s == null) {
+ return Optional.empty();
+ }
+ return Optional.of(VlanId.vlanId(Short.valueOf(s)));
+ }
+
+ public PortVlanConfig portVlanId(VlanId vlanId) {
+ if (vlanId == null) {
+ return (PortVlanConfig) setOrClear(S_TAG_KEY, (String) null);
+ }
+ return (PortVlanConfig) setOrClear(S_TAG_KEY, String.valueOf(vlanId.toShort()));
+ }
+}
\ No newline at end of file
diff --git a/ce-api/src/main/java/org/opencord/ce/api/models/codecs/CarrierEthernetBwProfileCodec.java b/ce-api/src/main/java/org/opencord/ce/api/models/codecs/CarrierEthernetBwProfileCodec.java
new file mode 100644
index 0000000..1865ab3
--- /dev/null
+++ b/ce-api/src/main/java/org/opencord/ce/api/models/codecs/CarrierEthernetBwProfileCodec.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2017-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.opencord.ce.api.models.codecs;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onlab.util.Bandwidth;
+import org.onosproject.codec.CodecContext;
+import org.onosproject.codec.JsonCodec;
+import org.opencord.ce.api.models.CarrierEthernetBandwidthProfile;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Codec for {@link CarrierEthernetBandwidthProfile}.
+ */
+public class CarrierEthernetBwProfileCodec extends JsonCodec<CarrierEthernetBandwidthProfile> {
+ private static final String ID = "bwpId";
+ private static final String CFG_ID = "cfgId";
+ private static final String TYPE = "bwpType";
+ private static final String CIR = "cir";
+ private static final String CBS = "cbs";
+ private static final String EIR = "eir";
+ private static final String EBS = "ebs";
+
+ @Override
+ public ObjectNode encode(CarrierEthernetBandwidthProfile bwProfile, CodecContext context) {
+ checkNotNull(bwProfile, "BW profile cannot be null");
+ ObjectNode result = context.mapper().createObjectNode();
+ result.put(ID, bwProfile.id())
+ .put(CFG_ID, bwProfile.cfgId())
+ .put(TYPE, bwProfile.type().name())
+ .put(CIR, bwProfile.cir().bps())
+ .put(EIR, bwProfile.eir().bps())
+ .put(CBS, bwProfile.cbs())
+ .put(EBS, bwProfile.ebs());
+ return result;
+ }
+
+ @Override
+ public CarrierEthernetBandwidthProfile decode(ObjectNode json, CodecContext context) {
+ return CarrierEthernetBandwidthProfile.builder()
+ .id(json.path(ID).asText())
+ .cfgId(json.path(CFG_ID).asText())
+ .type(CarrierEthernetBandwidthProfile.Type.valueOf(json.path(TYPE).asText()))
+ .cir(Bandwidth.bps(json.path(CIR).asDouble()))
+ .eir(Bandwidth.bps(json.path(EIR).asDouble()))
+ .cbs(json.path(CBS).asLong())
+ .ebs(json.path(EBS).asLong())
+ .build();
+ }
+}
diff --git a/ce-api/src/main/java/org/opencord/ce/api/models/codecs/CarrierEthernetConnectionCodec.java b/ce-api/src/main/java/org/opencord/ce/api/models/codecs/CarrierEthernetConnectionCodec.java
new file mode 100644
index 0000000..093c373
--- /dev/null
+++ b/ce-api/src/main/java/org/opencord/ce/api/models/codecs/CarrierEthernetConnectionCodec.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2017-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.opencord.ce.api.models.codecs;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onosproject.codec.CodecContext;
+import org.onosproject.codec.JsonCodec;
+import org.opencord.ce.api.models.CarrierEthernetConnection;
+import org.opencord.ce.api.models.EvcConnId;
+
+import java.time.Duration;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.opencord.ce.api.models.CarrierEthernetConnection.Type;
+import static org.opencord.ce.api.models.CarrierEthernetConnection.State;
+/**
+ * Codec for {@link org.opencord.ce.api.models.CarrierEthernetConnection}.
+ */
+public class CarrierEthernetConnectionCodec extends JsonCodec<CarrierEthernetConnection> {
+
+ private static final String ID = "connectionId";
+ private static final String CFG_ID = "cfgId";
+ private static final String TYPE = "type";
+ private static final String STATE = "state";
+ private static final String MAX_LATENCY = "maxLatency";
+
+ @Override
+ public ObjectNode encode(CarrierEthernetConnection connection, CodecContext context) {
+ checkNotNull(connection, "Java connection object cannot be null");
+ ObjectNode result = context.mapper().createObjectNode()
+ .put(ID, connection.id().id())
+ .put(CFG_ID, connection.cfgId())
+ .put(TYPE, connection.type().toString())
+ .put(STATE, connection.type().toString())
+ .put(MAX_LATENCY, connection.maxLatency().toString());
+ return result;
+ }
+
+ @Override
+ public CarrierEthernetConnection decode(ObjectNode json, CodecContext context) {
+ if (json == null || !json.isObject()) {
+ return null;
+ }
+
+ EvcConnId id = EvcConnId.of(json.path(ID).asText());
+ String cfgId = json.path(CFG_ID).asText();
+ Type type = Type.valueOf(json.path(TYPE).asText());
+ State state = State.valueOf(json.path(STATE).asText());
+ Duration maxLatency = Duration.parse(json.path(MAX_LATENCY).asText());
+ return null;
+ }
+
+}
diff --git a/ce-api/src/main/java/org/opencord/ce/api/models/codecs/CarrierEthernetEvcCodec.java b/ce-api/src/main/java/org/opencord/ce/api/models/codecs/CarrierEthernetEvcCodec.java
new file mode 100644
index 0000000..89bc338
--- /dev/null
+++ b/ce-api/src/main/java/org/opencord/ce/api/models/codecs/CarrierEthernetEvcCodec.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright 2017-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.opencord.ce.api.models.codecs;
+
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onosproject.codec.CodecContext;
+import org.onosproject.codec.JsonCodec;
+import org.opencord.ce.api.models.CarrierEthernetBandwidthProfile;
+import org.opencord.ce.api.models.CarrierEthernetNetworkInterface;
+import org.opencord.ce.api.models.CarrierEthernetUni;
+import org.opencord.ce.api.models.CarrierEthernetVirtualConnection;
+import org.opencord.ce.api.models.EvcConnId;
+import org.slf4j.Logger;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static org.onlab.util.Tools.nullIsIllegal;
+import static org.opencord.ce.api.models.CarrierEthernetEvcUtils.generateEvcType;
+import static org.opencord.ce.api.models.CarrierEthernetEvcUtils.generateMaxNumUni;
+import static org.opencord.ce.api.models.CarrierEthernetEvcUtils.generateUniSet;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Implementation of encoder for Alarm codec.
+ */
+public class CarrierEthernetEvcCodec extends JsonCodec<CarrierEthernetVirtualConnection> {
+
+ private static final String EVC_ID_REQUIRED = "EVC Id Must be specified";
+ private static final String EVC_TYPE_REQUIRED = "EVC Type Must be specified";
+ private static final String ARRAY_REQUIRED = "UNI array was not specified";
+
+ private final Logger log = getLogger(getClass());
+
+ @Override
+ public ObjectNode encode(CarrierEthernetVirtualConnection evc, CodecContext context) {
+ ObjectNode evcRoot = context.mapper().createObjectNode();
+ evcRoot.put("evcCfgId", evc.cfgId());
+ evcRoot.put("evcId", evc.id().id());
+ ArrayNode uniList = context.mapper()
+ .valueToTree(evc.uniSet().stream()
+ .map(CarrierEthernetNetworkInterface::id)
+ .collect(Collectors.toList()));
+ evcRoot.putArray("uniList").addAll(uniList);
+ evcRoot.put("maxNumUni", evc.maxNumUni());
+ CarrierEthernetUni uni = evc.uniSet().iterator().next();
+ evcRoot.put("vlanId", uni.ceVlanId().toString());
+ CarrierEthernetBandwidthProfile bwp = uni.bwp();
+ if (bwp != null) {
+ evcRoot.put("cir", bwp.cir().bps());
+ evcRoot.put("eir", bwp.eir().bps());
+ evcRoot.put("cbs", bwp.cbs());
+ evcRoot.put("ebs", bwp.ebs());
+ }
+ return evcRoot;
+ }
+
+ @Override
+ public CarrierEthernetVirtualConnection decode(ObjectNode json, CodecContext context) {
+ String argEvcCfgId = json.get("evcCfgId").asText(null);
+ String argEvcId = null;
+ if (json.has("evcId")) {
+ argEvcId = json.get("evcId").asText();
+ }
+ ArrayNode uniArray = nullIsIllegal((ArrayNode) json.get("uniList"),
+ ARRAY_REQUIRED);
+ List<String> uniList = new ArrayList<>();
+ uniArray.forEach(jsonNode -> uniList.add(jsonNode.asText()));
+ String evcTypeString = nullIsIllegal(json.get("evcType").asText(),
+ EVC_TYPE_REQUIRED);
+ int maxNumUni = -1;
+ if (json.has("maxNumUni")) {
+ maxNumUni = json.get("maxNumUni").asInt(-1);
+ }
+
+ short vlanId = -1;
+ if (json.has("vlanId")) {
+ vlanId = json.get("vlanId").shortValue();
+ }
+ double cir = json.get("cir").asDouble(0.0);
+ double eir = json.get("eir").asDouble(0.0);
+ long cbs = json.get("cbs").asLong(0L);
+ long ebs = json.get("ebs").asLong(0L);
+ log.info("Received REST call with parameters: " + "evcCfgId={}, evcId={}," +
+ " uniList={}, evcType={}, maxNumUni={}, vlanId={}, cir={}, " +
+ "eir={}, cbs={}, ebs={}", argEvcCfgId, argEvcId, uniList,
+ evcTypeString, maxNumUni, vlanId, cir, eir, cbs, ebs);
+ return CarrierEthernetVirtualConnection.builder()
+ .id(EvcConnId.of(argEvcId == null ? argEvcCfgId : argEvcId))
+ .cfgId(argEvcCfgId)
+ .type(generateEvcType(evcTypeString, uniList))
+ .maxNumUni(generateMaxNumUni(maxNumUni, evcTypeString, uniList))
+ .uniSet(generateUniSet(evcTypeString, uniList.subList(1, uniList.size()),
+ vlanId, uniList.get(0), argEvcCfgId, cir, eir,
+ cbs, ebs))
+ .build();
+ }
+
+}
diff --git a/ce-api/src/main/java/org/opencord/ce/api/models/codecs/CarrierEthernetNetworkInterfaceCodec.java b/ce-api/src/main/java/org/opencord/ce/api/models/codecs/CarrierEthernetNetworkInterfaceCodec.java
new file mode 100644
index 0000000..7395279
--- /dev/null
+++ b/ce-api/src/main/java/org/opencord/ce/api/models/codecs/CarrierEthernetNetworkInterfaceCodec.java
@@ -0,0 +1,164 @@
+/*
+ * Copyright 2017-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.opencord.ce.api.models.codecs;
+
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onlab.packet.VlanId;
+import org.onosproject.codec.CodecContext;
+import org.onosproject.codec.JsonCodec;
+import org.onosproject.net.ConnectPoint;
+import org.opencord.ce.api.models.CarrierEthernetBandwidthProfile;
+import org.opencord.ce.api.models.CarrierEthernetEnni;
+import org.opencord.ce.api.models.CarrierEthernetGenericNi;
+import org.opencord.ce.api.models.CarrierEthernetInni;
+import org.opencord.ce.api.models.CarrierEthernetNetworkInterface;
+import org.opencord.ce.api.models.CarrierEthernetUni;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.opencord.ce.api.models.CarrierEthernetNetworkInterface.Type;
+
+/**
+ * Codec for {@link org.opencord.ce.api.models.CarrierEthernetNetworkInterface}.
+ */
+public class CarrierEthernetNetworkInterfaceCodec extends JsonCodec<CarrierEthernetNetworkInterface> {
+
+ private static final String TYPE = "type";
+ private static final String CONNECT_POINT = "cp";
+ private static final String NI_ID = "niId";
+ private static final String CFG_ID = "cfgId";
+ private static final String BWP = "bwp";
+ private static final String C_TAGS = "cTags";
+ private static final String ROLE = "role";
+ private static final String CAPACITY = "capacity";
+ private static final String USED_CAPACITY = "usedCapacity";
+ private static final String S_TAG = "sTag";
+ private static final String C_TAG = "cTag";
+
+ @Override
+ public ObjectNode encode(CarrierEthernetNetworkInterface networkInterface, CodecContext context) {
+ checkNotNull(networkInterface, "Java networkInterface class cannot be null");
+ ObjectNode result = context.mapper().createObjectNode()
+ .put(CFG_ID, networkInterface.id())
+ .put(TYPE, networkInterface.type().toString())
+ .put(ROLE, networkInterface.role().toString());
+ if (networkInterface.capacity() != null) {
+ result.put(CAPACITY, networkInterface.capacity().bps());
+ }
+ if (networkInterface.usedCapacity() != null) {
+ result.put(USED_CAPACITY, networkInterface.usedCapacity().bps());
+ }
+ JsonCodec<ConnectPoint> cpCodec = context.codec(ConnectPoint.class);
+ result.set(CONNECT_POINT, cpCodec.encode(networkInterface.cp(), context));
+ switch (networkInterface.type()) {
+ case UNI:
+ CarrierEthernetUni uni = (CarrierEthernetUni) networkInterface;
+ JsonCodec<CarrierEthernetBandwidthProfile> bwpCodec =
+ context.codec(CarrierEthernetBandwidthProfile.class);
+ result.set(BWP, bwpCodec.encode(uni.bwp(), context));
+ ArrayNode ctags = context.mapper().createArrayNode();
+ uni.ceVlanIdSet().forEach(ceVlan -> ctags.add(ceVlan.toShort()));
+ result.set(C_TAGS, ctags);
+ break;
+ case INNI:
+ CarrierEthernetInni inni = (CarrierEthernetInni) networkInterface;
+ result.put(S_TAG, inni.sVlanId().toShort());
+ break;
+ case ENNI:
+ CarrierEthernetEnni enni = (CarrierEthernetEnni) networkInterface;
+ result.put(S_TAG, enni.sVlanId().toShort());
+ break;
+ case GENERIC:
+ default:
+ }
+ return result;
+ }
+
+ @Override
+ public CarrierEthernetNetworkInterface decode(ObjectNode json, CodecContext context) {
+ String id = json.path(NI_ID).asText();
+ String cfgId = json.path(CFG_ID).asText();
+ Type type = Type.valueOf(json.path(TYPE).asText());
+
+ JsonCodec<ConnectPoint> cpCodec = context.codec(ConnectPoint.class);
+ ConnectPoint cp = cpCodec.decode((ObjectNode) json.path(CONNECT_POINT), context);
+ CarrierEthernetNetworkInterface ni;
+ switch (type) {
+ case UNI:
+ JsonCodec<CarrierEthernetBandwidthProfile> bwpCodec =
+ context.codec(CarrierEthernetBandwidthProfile.class);
+ Set<VlanId> ceVlanIds = new HashSet<>();
+ json.path(C_TAGS).forEach(jsonCeVlan ->
+ ceVlanIds.add(VlanId.vlanId(jsonCeVlan.shortValue())));
+ CarrierEthernetUni.Role role = null;
+ for (CarrierEthernetUni.Role r : CarrierEthernetUni.Role.values()) {
+ if (r.toString().equals(json.path(ROLE).asText())) {
+ role = r;
+ break;
+ }
+ }
+ ni = CarrierEthernetUni.builder()
+ .cp(cp)
+ .cfgId(cfgId)
+ .bwp(bwpCodec.decode((ObjectNode) json.path(BWP), context))
+ .ceVlanId(ceVlanIds.iterator().next())
+ .role(role)
+ .build();
+ break;
+ case ENNI:
+ VlanId sTag = VlanId.vlanId(json.path(S_TAG).shortValue());
+ CarrierEthernetEnni.Role roleEnni = null;
+ for (CarrierEthernetEnni.Role r : CarrierEthernetEnni.Role.values()) {
+ if (r.toString().equals(json.path(ROLE).asText())) {
+ roleEnni = r;
+ break;
+ }
+ }
+ ni = CarrierEthernetEnni.builder()
+ .cp(cp)
+ .cfgId(cfgId)
+ .sVlanId(sTag)
+ .role(roleEnni)
+ .build();
+ break;
+ case INNI:
+ VlanId sTagInni = VlanId.vlanId(json.path(S_TAG).shortValue());
+ CarrierEthernetInni.Role roleInni = null;
+ for (CarrierEthernetInni.Role r : CarrierEthernetInni.Role.values()) {
+ if (r.toString().equals(json.path(ROLE).asText())) {
+ roleInni = r;
+ break;
+ }
+ }
+ ni = CarrierEthernetInni.builder()
+ .cp(cp)
+ .cfgId(cfgId)
+ .sVlanId(sTagInni)
+ .role(roleInni)
+ .build();
+ break;
+ case GENERIC:
+ default:
+ ni = new CarrierEthernetGenericNi(cp, cfgId);
+ }
+ return ni;
+ }
+
+}
diff --git a/ce-api/src/main/java/org/opencord/ce/api/models/codecs/CodecRegistrator.java b/ce-api/src/main/java/org/opencord/ce/api/models/codecs/CodecRegistrator.java
new file mode 100644
index 0000000..67b46ae
--- /dev/null
+++ b/ce-api/src/main/java/org/opencord/ce/api/models/codecs/CodecRegistrator.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2017-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.opencord.ce.api.models.codecs;
+
+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.onosproject.codec.CodecService;
+import org.opencord.ce.api.models.CarrierEthernetBandwidthProfile;
+import org.opencord.ce.api.models.CarrierEthernetForwardingConstruct;
+import org.opencord.ce.api.models.CarrierEthernetLogicalTerminationPoint;
+import org.opencord.ce.api.models.CarrierEthernetNetworkInterface;
+import org.opencord.ce.api.models.CarrierEthernetVirtualConnection;
+import org.slf4j.Logger;
+import static org.slf4j.LoggerFactory.getLogger;
+
+@Component(immediate = true)
+public class CodecRegistrator {
+ private final Logger log = getLogger(getClass());
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected CodecService codecService;
+
+ @Activate
+ public void activate() {
+ codecService.registerCodec(CarrierEthernetVirtualConnection.class,
+ new CarrierEthernetEvcCodec());
+ codecService.registerCodec(CarrierEthernetBandwidthProfile.class, new CarrierEthernetBwProfileCodec());
+ codecService.registerCodec(CarrierEthernetNetworkInterface.class,
+ new CarrierEthernetNetworkInterfaceCodec());
+ codecService.registerCodec(CarrierEthernetLogicalTerminationPoint.class,
+ new LogicalTerminationEndPointCodec());
+ codecService.registerCodec(CarrierEthernetForwardingConstruct.class,
+ new ForwardingConstructCodec());
+ log.info("Started");
+ }
+
+ @Deactivate
+ public void deactivate() {
+ codecService.unregisterCodec(CarrierEthernetVirtualConnection.class);
+ codecService.unregisterCodec(CarrierEthernetBandwidthProfile.class);
+ codecService.unregisterCodec(CarrierEthernetNetworkInterface.class);
+ codecService.unregisterCodec(CarrierEthernetForwardingConstruct.class);
+ codecService.unregisterCodec(CarrierEthernetLogicalTerminationPoint.class);
+ log.info("Stopped");
+ }
+}
\ No newline at end of file
diff --git a/ce-api/src/main/java/org/opencord/ce/api/models/codecs/ForwardingConstructCodec.java b/ce-api/src/main/java/org/opencord/ce/api/models/codecs/ForwardingConstructCodec.java
new file mode 100644
index 0000000..3c633fc
--- /dev/null
+++ b/ce-api/src/main/java/org/opencord/ce/api/models/codecs/ForwardingConstructCodec.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2017-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.opencord.ce.api.models.codecs;
+
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onlab.packet.VlanId;
+import org.onosproject.codec.CodecContext;
+import org.onosproject.codec.JsonCodec;
+import org.opencord.ce.api.models.CarrierEthernetConnection;
+import org.opencord.ce.api.models.CarrierEthernetForwardingConstruct;
+import org.opencord.ce.api.models.CarrierEthernetLogicalTerminationPoint;
+import org.opencord.ce.api.models.EvcConnId;
+
+import java.time.Duration;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Codec {@link CarrierEthernetForwardingConstruct}.
+ */
+public class ForwardingConstructCodec extends JsonCodec<CarrierEthernetForwardingConstruct> {
+ private static final String FC_ID = "fcId";
+ private static final String CFG_ID = "cfgId";
+ private static final String TYPE = "type";
+ private static final String STATE = "state";
+ private static final String MAX_LATENCY = "maxLatency";
+ private static final String VLAN_ID = "vlanId";
+ private static final String LTP_LIST = "ltpList";
+
+ @Override
+ public ObjectNode encode(CarrierEthernetForwardingConstruct fc, CodecContext context) {
+ JsonCodec<CarrierEthernetLogicalTerminationPoint> ltpCodec =
+ context.codec(CarrierEthernetLogicalTerminationPoint.class);
+ ObjectNode result = context.mapper().createObjectNode()
+ .put(FC_ID, fc.id().id())
+ .put(CFG_ID, fc.cfgId())
+ .put(TYPE, fc.type().toString())
+ .put(STATE, fc.type().toString())
+ .put(MAX_LATENCY, fc.maxLatency().toString());
+ result.put(VLAN_ID, fc.vlanId().toShort());
+ ArrayNode ltpsNode = context.mapper().createArrayNode();
+ fc.ltpSet().forEach(ltp ->
+ ltpsNode.add(ltpCodec.encode(ltp, context)));
+ result.set(LTP_LIST, ltpsNode);
+ return result;
+ }
+
+ @Override
+ public CarrierEthernetForwardingConstruct decode(ObjectNode json, CodecContext context) {
+ JsonCodec<CarrierEthernetLogicalTerminationPoint> ltpCodec =
+ context.codec(CarrierEthernetLogicalTerminationPoint.class);
+ Set<CarrierEthernetLogicalTerminationPoint> ltps =
+ new HashSet<>();
+ json.path(LTP_LIST).forEach(ltpJson ->
+ ltps.add(ltpCodec.decode((ObjectNode) ltpJson, context)));
+
+ CarrierEthernetForwardingConstruct fc = CarrierEthernetForwardingConstruct.builder()
+ .id(EvcConnId.of(json.path(FC_ID).asText()))
+ .cfgId(json.path(CFG_ID).asText())
+ .type(CarrierEthernetConnection.Type.valueOf(json.path(TYPE).asText()))
+ .maxLatency(Duration.parse(json.path(MAX_LATENCY).asText()))
+ .ltpSet(ltps)
+ .build();
+ fc.setVlanId(VlanId.vlanId(json.path(VLAN_ID).shortValue()));
+ return fc;
+ }
+}
diff --git a/ce-api/src/main/java/org/opencord/ce/api/models/codecs/LogicalTerminationEndPointCodec.java b/ce-api/src/main/java/org/opencord/ce/api/models/codecs/LogicalTerminationEndPointCodec.java
new file mode 100644
index 0000000..10061fd
--- /dev/null
+++ b/ce-api/src/main/java/org/opencord/ce/api/models/codecs/LogicalTerminationEndPointCodec.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2017-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.opencord.ce.api.models.codecs;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onosproject.codec.CodecContext;
+import org.onosproject.codec.JsonCodec;
+import org.opencord.ce.api.models.CarrierEthernetLogicalTerminationPoint;
+import org.opencord.ce.api.models.CarrierEthernetNetworkInterface;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.opencord.ce.api.models.CarrierEthernetLogicalTerminationPoint.Role;
+
+/**
+ * Codec for {@link CarrierEthernetLogicalTerminationPoint}.
+ */
+public class LogicalTerminationEndPointCodec extends JsonCodec<CarrierEthernetLogicalTerminationPoint> {
+
+ private static final String ROLE = "role";
+ private static final String LTP_ID = "ltpId";
+ private static final String CFG_ID = "cfgId";
+ private static final String NETWORK_INTERFACE = "ni";
+
+ @Override
+ public ObjectNode encode(CarrierEthernetLogicalTerminationPoint ltp, CodecContext context) {
+ checkNotNull(ltp, "Java ltp object cannot be null");
+
+ JsonCodec<CarrierEthernetNetworkInterface> niCodec =
+ context.codec(CarrierEthernetNetworkInterface.class);
+
+ ObjectNode result = context.mapper().createObjectNode()
+ .put(LTP_ID, ltp.id())
+ .put(CFG_ID, ltp.cfgId())
+ .put(ROLE, ltp.role().toString());
+ result.set(NETWORK_INTERFACE, niCodec.encode(ltp.ni(), context));
+ return result;
+ }
+
+ @Override
+ public CarrierEthernetLogicalTerminationPoint decode(ObjectNode json, CodecContext context) {
+
+ String ltpId = json.path(LTP_ID).asText();
+ String cfgId = json.path(CFG_ID).asText();
+ JsonCodec<CarrierEthernetNetworkInterface> niCodec =
+ context.codec(CarrierEthernetNetworkInterface.class);
+ ObjectNode niJson = get(json, NETWORK_INTERFACE);
+ CarrierEthernetNetworkInterface networkInterface =
+ niCodec.decode(niJson, context);
+ CarrierEthernetLogicalTerminationPoint ltp =
+ new CarrierEthernetLogicalTerminationPoint(cfgId, networkInterface);
+ for (Role r : Role.values()) {
+ if (r.toString().equals(json.path(ROLE).asText())) {
+ ltp.setRole(r);
+ }
+ }
+ return ltp;
+ }
+}
diff --git a/ce-api/src/main/java/org/opencord/ce/api/models/codecs/package-info.java b/ce-api/src/main/java/org/opencord/ce/api/models/codecs/package-info.java
new file mode 100644
index 0000000..060acc1
--- /dev/null
+++ b/ce-api/src/main/java/org/opencord/ce/api/models/codecs/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-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.
+ */
+
+/**
+ * Json/Java codecs package.
+ */
+package org.opencord.ce.api.models.codecs;
\ No newline at end of file
diff --git a/ce-api/src/main/java/org/opencord/ce/api/models/package-info.java b/ce-api/src/main/java/org/opencord/ce/api/models/package-info.java
new file mode 100644
index 0000000..6d815fe
--- /dev/null
+++ b/ce-api/src/main/java/org/opencord/ce/api/models/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-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.
+ */
+
+/**
+ * VEE APIs.
+ */
+package org.opencord.ce.api.models;
\ No newline at end of file
diff --git a/ce-api/src/main/java/org/opencord/ce/api/services/MetroNetworkProvisionerService.java b/ce-api/src/main/java/org/opencord/ce/api/services/MetroNetworkProvisionerService.java
new file mode 100644
index 0000000..c57bccc
--- /dev/null
+++ b/ce-api/src/main/java/org/opencord/ce/api/services/MetroNetworkProvisionerService.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2017-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.opencord.ce.api.services;
+
+
+import com.google.common.annotations.Beta;
+import org.opencord.ce.api.models.CarrierEthernetForwardingConstruct;
+
+/**
+ * Service interface for provisioning of Carrier Ethernet connections.
+ */
+@Beta
+public interface MetroNetworkProvisionerService {
+ /**
+ * Creates bandwidth profiles at the UNIs of an FC.
+ *
+ * @param fc the forwarding construct
+ */
+ void createBandwidthProfiles(CarrierEthernetForwardingConstruct fc);
+
+ /**
+ * Applies bandwidth profiles to the UNIs of an FC.
+ *
+ * @param fc the forwarding construct
+ */
+ void applyBandwidthProfiles(CarrierEthernetForwardingConstruct fc);
+
+ /**
+ * Removes bandwidth profiles from the UNIs of an FC.
+ *
+ * @param fc the forwarding construct
+ */
+ void removeBandwidthProfiles(CarrierEthernetForwardingConstruct fc);
+
+ /**
+ * Establishes connectivity for the provided FC by installing all necessary forwarding rules.
+ *
+ * @param fc the forwarding construct
+ */
+ void setupConnectivity(CarrierEthernetForwardingConstruct fc);
+
+ /**
+ * Removes connectivity for the provided FC by removing all installed forwarding rules.
+ *
+ * @param fc the forwarding construct
+ */
+ void removeConnectivity(CarrierEthernetForwardingConstruct fc);
+
+}
+
diff --git a/ce-api/src/main/java/org/opencord/ce/api/services/MetroNetworkVirtualNodeService.java b/ce-api/src/main/java/org/opencord/ce/api/services/MetroNetworkVirtualNodeService.java
new file mode 100644
index 0000000..2f1894d
--- /dev/null
+++ b/ce-api/src/main/java/org/opencord/ce/api/services/MetroNetworkVirtualNodeService.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2017-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.opencord.ce.api.services;
+
+import org.opencord.ce.api.models.CarrierEthernetForwardingConstruct;
+import org.opencord.ce.api.models.CarrierEthernetNetworkInterface;
+import org.opencord.ce.api.models.CarrierEthernetUni;
+import org.opencord.ce.api.models.EvcConnId;
+
+import java.util.Set;
+
+/**
+ * Boundary interface between global Carrier Ethernet orchestration and local-site
+ * Carrier Ethernet service provisioning.
+ */
+public interface MetroNetworkVirtualNodeService {
+
+ /**
+ * Creates and submits FlowObjectives depending on role of the device in the FC and ingress/egress NI types.
+ *
+ * @param fc the forwarding construct
+ * @param srcNi the source network interface
+ * @param dstNiSet the set of destination network interfaces
+ */
+ void setNodeForwarding(CarrierEthernetForwardingConstruct fc, CarrierEthernetNetworkInterface srcNi,
+ Set<CarrierEthernetNetworkInterface> dstNiSet);
+
+ /**
+ * Creates and stores meters based on the UNI's bandwidth profile.
+ *
+ * @param fc the forwarding construct
+ * @param uni the user to network interface
+ */
+ void createBandwidthProfileResources(CarrierEthernetForwardingConstruct fc, CarrierEthernetUni uni);
+
+ /**
+ * Applies meters to flows.
+ *
+ * @param fc the forwarding construct
+ * @param uni the user to network interface
+ */
+ void applyBandwidthProfileResources(CarrierEthernetForwardingConstruct fc, CarrierEthernetUni uni);
+
+ /**
+ * Removes the meters associated with a specific UNI of an FC.
+ *
+ * @param fc the forwarding construct
+ * @param uni the user to network interface
+ */
+ void removeBandwidthProfileResources(CarrierEthernetForwardingConstruct fc, CarrierEthernetUni uni);
+
+ /**
+ * Removes all installed flow objectives associated with a specific FC.
+ *
+ * @param fcId the forwarding construct
+ */
+ void removeAllForwardingResources(EvcConnId fcId);
+}
diff --git a/ce-api/src/main/java/org/opencord/ce/api/services/MetroOrchestrationService.java b/ce-api/src/main/java/org/opencord/ce/api/services/MetroOrchestrationService.java
new file mode 100644
index 0000000..f0d158f
--- /dev/null
+++ b/ce-api/src/main/java/org/opencord/ce/api/services/MetroOrchestrationService.java
@@ -0,0 +1,248 @@
+/*
+ * Copyright 2017-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.opencord.ce.api.services;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.net.ConnectPoint;
+import org.opencord.ce.api.models.CarrierEthernetForwardingConstruct;
+import org.opencord.ce.api.models.CarrierEthernetLogicalTerminationPoint;
+import org.opencord.ce.api.models.CarrierEthernetUni;
+import org.opencord.ce.api.models.CarrierEthernetVirtualConnection;
+import org.opencord.ce.api.models.EvcConnId;
+
+import java.util.Map;
+import java.util.Set;
+
+import static org.opencord.ce.api.models.CarrierEthernetNetworkInterface.Type;
+
+/**
+ * Service interface for Carrier Ethernet.
+ *
+ * Defines interactions with CE concepts such as Ethernet Virtual Circuit (EVC), Forwarding Construct (FC),
+ * Logical Termination Point (LTP), and User to Network Interface (UNI).
+ */
+@Beta
+public interface MetroOrchestrationService {
+ /**
+ * Returns the map of installed EVCs.
+ *
+ * @return map of installed EVCs
+ */
+ Map<EvcConnId, CarrierEthernetVirtualConnection> evcMap();
+
+ /**
+ * Get an installed EVC using its id.
+ *
+ * @param evcId the EVC id
+ * @return the EVC representation or null if the EVC doesn't exist
+ */
+ CarrierEthernetVirtualConnection getEvc(EvcConnId evcId);
+
+ // TODO: Add method to remove a UNI from an already installed EVC
+
+ /**
+ * Establish connectivity according to the EVC type (E-Line, E-Tree, E-LAN) and the EVC parameters.
+ *
+ * @param evc the EVC representation
+ * @return the (potentially modified) EVC that was installed or null in case of failure
+ */
+ CarrierEthernetVirtualConnection installEvc(CarrierEthernetVirtualConnection evc);
+
+ /**
+ * Re-establish connectivity for an existing EVC.
+ *
+ * @param evc the updated EVC definition
+ * @return the (potentially modified) EVC that was installed or null if EVC connectivity could not be established
+ */
+ CarrierEthernetVirtualConnection updateEvc(CarrierEthernetVirtualConnection evc);
+
+
+ /**
+ * Removes all resources associated with a specific installed EVC.
+ *
+ * @param evcId the EVC id
+ */
+ void removeEvc(EvcConnId evcId);
+
+
+ /**
+ * Removes all installed EVCs and the associated resources.
+ * <p>
+ * This will be called either from the deactivate method or as a response to a CLI/REST command.
+ */
+ void removeAllEvcs();
+
+ /**
+ * Enable or disable EVC fragmentation into FCs.
+ *
+ * @param evcFragmentationEnabled true to enable fragmentation, false otherwise
+ */
+ void setEvcFragmentation(boolean evcFragmentationEnabled);
+
+
+ /**
+ * Checks the fragmentation state of the EVC.
+ *
+ * @return true if fragmentation is enabled, false otherwise
+ */
+ boolean getEvcFragmentation();
+
+ /**
+ * Set the EVC fragmentation flag to the value before its last change.
+ *
+ */
+ void resetEvcFragmentation();
+
+ /**
+ * Get the map containing all installed FCs.
+ *
+ * @return the FC map
+ */
+ Map<EvcConnId, CarrierEthernetForwardingConstruct> fcMap();
+
+ /**
+ * Get an installed FC using its id.
+ *
+ * @param fcId the FC id
+ * @return the FC representation or null if the EVC doesn't exist
+ */
+ CarrierEthernetForwardingConstruct getFc(EvcConnId fcId);
+
+ /**
+ * Installs all resources associated with a specific FC.
+ *
+ * @param fc the FC to install
+ * @return the FC that was installed
+ */
+ CarrierEthernetForwardingConstruct installFc(CarrierEthernetForwardingConstruct fc);
+
+ /**
+ * Re-establish connectivity for an existing FC.
+ *
+ * @param fc the updated FC representation
+ * @return the possibly modified FC that was installed or null if updated FC could not be installed
+ */
+ CarrierEthernetForwardingConstruct updateFc(CarrierEthernetForwardingConstruct fc);
+
+ /**
+ * Removes all resources associated with a specific FC.
+ *
+ * @param fcId the FC id
+ * @return the FC that was removed or null if removal failed
+ */
+ CarrierEthernetForwardingConstruct removeFc(EvcConnId fcId);
+
+ /**
+ * Removes all resources associated with the application.
+ *
+ * This will be called either from the deactivate method or as a response to a CLI command.
+ */
+ void removeAllFcs();
+
+ /**
+ * Get the map containing all global UNIs.
+ *
+ * @return the global UNI map
+ */
+ Map<String, CarrierEthernetUni> getUniMap();
+
+ /**
+ * Adds a potential UNI to the global UNI map if they are not already there.
+ *
+ * @param uni the potential UNI to add to global UNI map
+ * @return the UNI that was added or null if UNI existed already
+ */
+ CarrierEthernetUni addGlobalUni(CarrierEthernetUni uni);
+
+ /**
+ * Remove an UNI from the set of global UNIs.
+ *
+ * @param uniId the id of the UNI to be removed
+ * @return the UNI that was removed or null in case of failure (didn't exist of refCount was not 0)
+ */
+ CarrierEthernetUni removeGlobalUni(String uniId);
+
+ // TODO: Add removeAllGlobalUnis method (or command only?)
+
+ /**
+ * Creates a new UNI associated with the provided connect point.
+ *
+ * Conditions for validating an UNI:
+ * - ConnectPoint deviceId and Port are valid
+ * - Port is enabled
+ *
+ * @param cp the connect point to be associated with the generated UNI
+ * @return a new validated UNI or null if the validation failed
+ */
+ CarrierEthernetUni generateUni(ConnectPoint cp);
+
+ /**
+ * Returns all potential UNIs from the topology.
+ *
+ * @param excludeAdded indicates that UNIs already added in the UNI map should not be in the returned set
+ * @param includeRemoved indicates that UNIs explicitly removed from the UNI map should be in the returned set
+ * @return set of all potential UNIs in the topology
+ */
+ Set<CarrierEthernetUni> getUnisFromTopo(boolean excludeAdded, boolean includeRemoved);
+
+ /**
+ * Get the map containing all global LTPs.
+ *
+ * @return the global LTP map
+ */
+ Map<String, CarrierEthernetLogicalTerminationPoint> ltpMap();
+
+ /**
+ * Adds a potential LTP and its UNI or pair INNI to the global LTP/UNI maps if they are not already there.
+ *
+ * @param ltp the potential LTP to add to global LTP map
+ * @return the LTP that was added or null if it already existed
+ */
+ CarrierEthernetLogicalTerminationPoint addGlobalLtp(CarrierEthernetLogicalTerminationPoint ltp);
+
+ /**
+ * Remove an LTP from the set of global LTPs, as well as the corresponding INNI LTP at the other end of the link.
+ *
+ * @param ltpId the id of the LTP to be removed
+ * @return the LTP that was removed or null in case of failure (didn't exist of refCount was not 0)
+ */
+ CarrierEthernetLogicalTerminationPoint removeGlobalLtp(String ltpId);
+
+ // TODO: Add removeAllGlobalLtps method (or command only?)
+
+ /**
+ * Creates a new LTP of the provided type and associated with the provided connect point.
+ *
+ * Conditions for validating an LTP:
+ * - ConnectPoint deviceId and Port are valid
+ * - Port is enabled
+ *
+ * @param cp the connect point to be associated with the generated LTP
+ * @param ltpType the type of the LTP to be generated (UNI/INNI/ENNI)
+ * @return a new validated LTP or null if the validation failed
+ */
+ CarrierEthernetLogicalTerminationPoint generateLtp(ConnectPoint cp, Type ltpType);
+
+ /**
+ * Returns all potential LTPs from the topology.
+ *
+ * @param excludeAdded indicates that LTPs already added in the LTP map should not be in the returned set
+ * @param includeRemoved indicates that LTPs explicitly removed from the LTP map should be in the returned set
+ * @return set of all potential LTPs in the topology
+ */
+ Set<CarrierEthernetLogicalTerminationPoint> getLtpsFromTopo(boolean excludeAdded, boolean includeRemoved);
+}
diff --git a/ce-api/src/main/java/org/opencord/ce/api/services/channel/ControlChannelListenerService.java b/ce-api/src/main/java/org/opencord/ce/api/services/channel/ControlChannelListenerService.java
new file mode 100644
index 0000000..f85e13d
--- /dev/null
+++ b/ce-api/src/main/java/org/opencord/ce/api/services/channel/ControlChannelListenerService.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2017-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.opencord.ce.api.services.channel;
+
+import org.opencord.ce.api.services.MetroNetworkVirtualNodeService;
+
+import java.util.Set;
+
+/**
+ * Service used by the southbound components of the global ONOS to listen for EVCs setup.
+ */
+public interface ControlChannelListenerService {
+
+ void addListener(MetroNetworkVirtualNodeService listener);
+
+ void removeListener(MetroNetworkVirtualNodeService listener);
+
+ Set<MetroNetworkVirtualNodeService> listeners();
+}
diff --git a/ce-api/src/main/java/org/opencord/ce/api/services/channel/RequestCallback.java b/ce-api/src/main/java/org/opencord/ce/api/services/channel/RequestCallback.java
new file mode 100644
index 0000000..9d9b0e2
--- /dev/null
+++ b/ce-api/src/main/java/org/opencord/ce/api/services/channel/RequestCallback.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2017-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.opencord.ce.api.services.channel;
+
+import javax.ws.rs.core.Response;
+
+/**
+ * HTTP request callback.
+ */
+public interface RequestCallback {
+
+ // called upon a successful network task
+ default void onSuccess(Response response){}
+
+ // called upon a failured network task
+ default void onError(Response response){}
+}
diff --git a/ce-api/src/main/java/org/opencord/ce/api/services/channel/Symbols.java b/ce-api/src/main/java/org/opencord/ce/api/services/channel/Symbols.java
new file mode 100644
index 0000000..ea28756
--- /dev/null
+++ b/ce-api/src/main/java/org/opencord/ce/api/services/channel/Symbols.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2017-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.opencord.ce.api.services.channel;
+
+
+/**
+ * HTTP resource paths.
+ */
+public final class Symbols {
+
+ private Symbols() {
+ }
+
+ public static final String POST = "post";
+ public static final String GET = "get";
+ public static final String DELETE = "delete";
+ public static final String HTTP = "http";
+ public static final String DOUBLESLASH = "//";
+ public static final String L_BRACKET = "{";
+ public static final String R_BRACKET = "}";
+ public static final String QUOTES = "\"";
+ public static final String COLON = ":";
+ public static final String OK = "ok";
+ public static final String MASTER_IP = "masterIp";
+ public static final String RESULT = "result";
+ public static final String NO_ENDPOINT_AVAILABLE = "unavailable";
+
+ public static final String MASTER_API_NO_IP_BODY = L_BRACKET
+ + QUOTES + RESULT + QUOTES + COLON + QUOTES + NO_ENDPOINT_AVAILABLE + QUOTES
+ + R_BRACKET;
+
+ public static final String BASE_URL = "/ecord";
+
+ public static final String MASTER = "/master";
+
+ public static final String FC = "fc";
+ public static final String SRC_NI = "srcNi";
+ public static final String DST_NI_LIST = "dstNiList";
+ public static final String UNI = "uni";
+
+ public static final String FC_ID = "fcId";
+ // ======== Forwarding Construct data ====== //
+ public static final String FC_TAG = "fcTag";
+ public static final String FC_INGRESS_CP = "fcIngressCp";
+ public static final String FC_TYPE = "fcType";
+ public static final String INGRESS_NI_TYPE = "ingressNiType";
+ public static final String INGRESS_FC_TAG = "ingressFcTag";
+ public static final String CUSTOMER_TAG = "customerTag";
+ public static final String FC_EGRESS_LST = "fcEgressList";
+ public static final String FC_EGRESS_CP = "fcEgressCp";
+ public static final String FC_EGRESS_TYPE = "fcEgressType";
+
+ // ======== Bandwidth profile data ====== //
+ public static final String BW_PROFILE = "bwProfile";
+ public static final String CIR = "cir";
+ public static final String EIR = "eir";
+ public static final String CBS = "cbs";
+ public static final String EBS = "ebs";
+ public static final String UNI_CP = "uniCp";
+
+
+ // ===== Device and Port annotations ==== //
+ public static final String DEVICE_ID = "deviceId";
+ public static final String MEF_PORT_TYPE = "mefPortType";
+
+
+}
+
diff --git a/ce-api/src/main/java/org/opencord/ce/api/services/channel/package-info.java b/ce-api/src/main/java/org/opencord/ce/api/services/channel/package-info.java
new file mode 100644
index 0000000..d66fa7e
--- /dev/null
+++ b/ce-api/src/main/java/org/opencord/ce/api/services/channel/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-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.
+ */
+
+/**
+ * Communication channel between global orchestrator and local sites.
+ */
+package org.opencord.ce.api.services.channel;
\ No newline at end of file
diff --git a/ce-api/src/main/java/org/opencord/ce/api/services/package-info.java b/ce-api/src/main/java/org/opencord/ce/api/services/package-info.java
new file mode 100644
index 0000000..5f6a3a2
--- /dev/null
+++ b/ce-api/src/main/java/org/opencord/ce/api/services/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-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.
+ */
+
+/**
+ * Service APIs for Carrier Ethernet.
+ */
+package org.opencord.ce.api.services;
\ No newline at end of file
diff --git a/ce-api/src/main/java/org/opencord/ce/api/services/virtualprovider/DefaultDomainVirtualDevice.java b/ce-api/src/main/java/org/opencord/ce/api/services/virtualprovider/DefaultDomainVirtualDevice.java
new file mode 100644
index 0000000..122c309
--- /dev/null
+++ b/ce-api/src/main/java/org/opencord/ce/api/services/virtualprovider/DefaultDomainVirtualDevice.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2017-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.opencord.ce.api.services.virtualprovider;
+
+
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.domain.DomainId;
+
+import java.util.Objects;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+
+/**
+ * Default implementation of a domain device.
+ */
+public class DefaultDomainVirtualDevice implements DomainVirtualDevice {
+ private final DeviceId deviceId;
+ private final DomainId domainId;
+
+ public DefaultDomainVirtualDevice(DeviceId deviceId, DomainId domainId) {
+ this.deviceId = deviceId;
+ this.domainId = domainId;
+ }
+
+ @Override
+ public DeviceId deviceId() {
+ return deviceId;
+ }
+
+ @Override
+ public DomainId domainId() {
+ return domainId;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(super.hashCode(), deviceId, domainId);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof DefaultDomainVirtualDevice) {
+ final DefaultDomainVirtualDevice other = (DefaultDomainVirtualDevice) obj;
+ return Objects.equals(this.deviceId, other.deviceId()) &&
+ Objects.equals(this.domainId, other.domainId());
+
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(this)
+ .add("deviceId", deviceId.toString())
+ .add("domainId", domainId)
+ .toString();
+ }
+}
diff --git a/ce-api/src/main/java/org/opencord/ce/api/services/virtualprovider/DomainElement.java b/ce-api/src/main/java/org/opencord/ce/api/services/virtualprovider/DomainElement.java
new file mode 100644
index 0000000..94e8367
--- /dev/null
+++ b/ce-api/src/main/java/org/opencord/ce/api/services/virtualprovider/DomainElement.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2017-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.opencord.ce.api.services.virtualprovider;
+
+import org.onosproject.net.domain.DomainId;
+
+/**
+ * Interface implemented by the domain topology elements.
+ */
+public interface DomainElement {
+
+ /**
+ * Returns the domain id the element belongs to.
+ * @return domain id
+ */
+ DomainId domainId();
+}
diff --git a/ce-api/src/main/java/org/opencord/ce/api/services/virtualprovider/DomainVirtualDevice.java b/ce-api/src/main/java/org/opencord/ce/api/services/virtualprovider/DomainVirtualDevice.java
new file mode 100644
index 0000000..acc1d06
--- /dev/null
+++ b/ce-api/src/main/java/org/opencord/ce/api/services/virtualprovider/DomainVirtualDevice.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2017-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.opencord.ce.api.services.virtualprovider;
+
+import org.onosproject.net.DeviceId;
+
+/**
+ * Domain virtual device.
+ * Represents an aggregated set of ports associated to an underlying domain.
+ *
+ */
+public interface DomainVirtualDevice extends DomainElement {
+
+ /**
+ * Returns the device ID.
+ * @return device identifier
+ */
+ DeviceId deviceId();
+
+}
diff --git a/ce-api/src/main/java/org/opencord/ce/api/services/virtualprovider/EcordDeviceProviderService.java b/ce-api/src/main/java/org/opencord/ce/api/services/virtualprovider/EcordDeviceProviderService.java
new file mode 100644
index 0000000..1b099ed
--- /dev/null
+++ b/ce-api/src/main/java/org/opencord/ce/api/services/virtualprovider/EcordDeviceProviderService.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2017-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.opencord.ce.api.services.virtualprovider;
+
+
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.Port;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.device.PortDescription;
+import org.onosproject.net.domain.DomainId;
+
+import java.util.List;
+
+/**
+ * Service used by the southbound communication channel to notify virtual device presence.
+ */
+public interface EcordDeviceProviderService {
+
+ /**
+ * Signals the domain provider to connect a device of another domain.
+ *
+ * @param domainVirtualDevice device object
+ */
+ void connectRemoteDevice(DomainVirtualDevice domainVirtualDevice);
+
+ /**
+ * Adds or updates ports on a remote domain.
+ *
+ * @param domainId domain ID
+ * @param deviceId device ID
+ * @param ports list of port descriptions
+ */
+ void addOrUpdateRemotePorts(DomainId domainId, DeviceId deviceId, List<PortDescription> ports);
+
+ /**
+ * Signals the domain provider that a specific domain has added a new port to a device.
+ *
+ * @param domainId domain identifier
+ * @param deviceId device identifier
+ * @param port port
+ */
+ void addRemotePort(DomainId domainId, DeviceId deviceId, Port port);
+
+ /**
+ * Signals a remote port update.
+ *
+ * @param domainId domain identifier
+ * @param deviceId device identifier
+ * @param port port description
+ */
+ void updateRemotePortState(DomainId domainId, DeviceId deviceId, Port port);
+
+ /**
+ * Signals the disconnection of a remote domain device.
+ *
+ * @param domainId domain identifier
+ * @param deviceId device identifier
+ */
+ void disconnectRemoteDevice(DomainId domainId, DeviceId deviceId);
+
+ /**
+ * Signals the deletion of a remote domain device port.
+ * @param domainId domain identifier
+ * @param deviceId device identifier
+ * @param portNumber port identifier
+ */
+ void removeRemotePort(DomainId domainId, DeviceId deviceId, PortNumber portNumber);
+}
diff --git a/ce-api/src/main/java/org/opencord/ce/api/services/virtualprovider/LinkId.java b/ce-api/src/main/java/org/opencord/ce/api/services/virtualprovider/LinkId.java
new file mode 100644
index 0000000..cd51403
--- /dev/null
+++ b/ce-api/src/main/java/org/opencord/ce/api/services/virtualprovider/LinkId.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2017-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.opencord.ce.api.services.virtualprovider;
+
+import org.onlab.util.Identifier;
+
+/**
+ * Domain link identifier class.
+ */
+public class LinkId extends Identifier<String> {
+
+ public LinkId(String identifier) {
+ super(identifier);
+ }
+
+ public static LinkId linkId(String id) {
+
+ return new LinkId(id);
+ }
+}
diff --git a/ce-api/src/main/java/org/opencord/ce/api/services/virtualprovider/package-info.java b/ce-api/src/main/java/org/opencord/ce/api/services/virtualprovider/package-info.java
new file mode 100644
index 0000000..37711e3
--- /dev/null
+++ b/ce-api/src/main/java/org/opencord/ce/api/services/virtualprovider/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-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.
+ */
+
+/**
+ * APIs for virtual device providers.
+ */
+package org.opencord.ce.api.services.virtualprovider;
\ No newline at end of file
diff --git a/global/app/app.xml b/global/app/app.xml
new file mode 100644
index 0000000..37f2a35
--- /dev/null
+++ b/global/app/app.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ ~ Copyright 2017-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.
+ -->
+<app name="org.opencord.ce.global.app" origin="ON.Lab" version="${project.version}"
+ category="Utility" url="http://opencord.org" title="Enterprise CORD"
+ featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features"
+ features="${project.artifactId}">
+ <description>${project.description}</description>
+ <artifact>mvn:${project.groupId}/orchestration/${project.version}</artifact>
+ <artifact>mvn:${project.groupId}/global-channel/${project.version}</artifact>
+ <artifact>mvn:${project.groupId}/virtualprovider/${project.version}</artifact>
+ <!-- <artifact>mvn:${project.groupId}/onos-app-icona-driver/${project.version}</artifact> -->
+</app>
diff --git a/global/app/features.xml b/global/app/features.xml
new file mode 100644
index 0000000..bcc7471
--- /dev/null
+++ b/global/app/features.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+
+<!--
+ ~ Copyright 2017-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.
+ -->
+<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}">
+ <feature name="${project.artifactId}" version="${project.version}"
+ description="${project.description}">
+ <bundle>mvn:${project.groupId}/orchestration/${project.version}</bundle>
+ <bundle>mvn:${project.groupId}/global-channel/${project.version}</bundle>
+ <bundle>mvn:${project.groupId}/virtualprovider/${project.version}</bundle>
+ <!-- <bundle>mvn:${project.groupId}/onos-app-icona-driver/${project.version}</bundle> -->
+ </feature>
+</features>
\ No newline at end of file
diff --git a/global/app/pom.xml b/global/app/pom.xml
new file mode 100644
index 0000000..0c6f282
--- /dev/null
+++ b/global/app/pom.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2017-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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.opencord.ce</groupId>
+ <artifactId>global</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>ecord-global-app</artifactId>
+ <packaging>pom</packaging>
+ <version>1.0.0-SNAPSHOT</version>
+
+ <description>Java application bundling orchestration,
+ HTTP communication and topology provider component
+ </description>
+
+ <properties>
+ <onos.app.name>org.opencord.ce.global</onos.app.name>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.opencord.ce</groupId>
+ <artifactId>orchestration</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opencord.ce</groupId>
+ <artifactId>global-channel</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opencord.ce</groupId>
+ <artifactId>virtualprovider</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+</project>
\ No newline at end of file
diff --git a/global/ce-orchestration/pom.xml b/global/ce-orchestration/pom.xml
new file mode 100644
index 0000000..fb2ed3c
--- /dev/null
+++ b/global/ce-orchestration/pom.xml
@@ -0,0 +1,112 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2015-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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.opencord.ce</groupId>
+ <artifactId>global</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>orchestration</artifactId>
+ <packaging>bundle</packaging>
+
+ <description>Orchestration logic of Carrier Ethernet Forwarding Constructs</description>
+
+ <properties>
+ <web.context>/carrierethernet</web.context>
+ <onos.app.name>org.opencord.ce.global.orchestration</onos.app.name>
+ <onos.version>1.10.6</onos.version>
+ <onos.app.url>http://opencord.org</onos.app.url>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-api</artifactId>
+ <version>${onos.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onlab-rest</artifactId>
+ <version>${onos.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-cli</artifactId>
+ <version>${onos.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.karaf.shell</groupId>
+ <artifactId>org.apache.karaf.shell.console</artifactId>
+ <version>3.0.5</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <_wab>src/main/webapp/</_wab>
+ <Bundle-SymbolicName>
+ ${project.groupId}.${project.artifactId}
+ </Bundle-SymbolicName>
+ <Import-Package>
+ *,org.glassfish.jersey.servlet
+ </Import-Package>
+ <Web-ContextPath>${web.context}</Web-ContextPath>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+
+ <repositories>
+ <repository>
+ <id>snapshots</id>
+ <url>https://oss.sonatype.org/content/repositories/snapshots</url>
+ <releases><enabled>false</enabled></releases>
+ </repository>
+ </repositories>
+
+ <pluginRepositories>
+ <pluginRepository>
+ <id>snapshots</id>
+ <url>https://oss.sonatype.org/content/repositories/snapshots</url>
+ <releases><enabled>false</enabled></releases>
+ </pluginRepository>
+ </pluginRepositories>
+
+</project>
diff --git a/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/MetroNetworkProvisioner.java b/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/MetroNetworkProvisioner.java
new file mode 100644
index 0000000..99c7c05
--- /dev/null
+++ b/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/MetroNetworkProvisioner.java
@@ -0,0 +1,317 @@
+/*
+ * Copyright 2017-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.opencord.ce.global.orchestration;
+
+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.opencord.ce.api.services.channel.ControlChannelListenerService;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DefaultLink;
+import org.onosproject.net.Link;
+import org.onosproject.net.Path;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.provider.ProviderId;
+import org.onosproject.net.topology.PathService;
+import org.onosproject.net.topology.TopologyService;
+import org.opencord.ce.api.models.CarrierEthernetConnection;
+import org.opencord.ce.api.models.CarrierEthernetForwardingConstruct;
+import org.opencord.ce.api.models.CarrierEthernetGenericNi;
+import org.opencord.ce.api.models.CarrierEthernetLogicalTerminationPoint;
+import org.opencord.ce.api.models.CarrierEthernetNetworkInterface;
+import org.opencord.ce.api.models.CarrierEthernetSpanningTreeWeight;
+import org.opencord.ce.api.models.CarrierEthernetUni;
+import org.opencord.ce.api.models.CarrierEthernetVirtualConnection;
+import org.opencord.ce.api.services.MetroNetworkProvisionerService;
+import org.slf4j.Logger;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import static org.onosproject.net.DefaultEdgeLink.createEdgeLink;
+import static org.slf4j.LoggerFactory.getLogger;
+import static org.opencord.ce.api.models.CarrierEthernetLogicalTerminationPoint.Role;
+import static org.opencord.ce.api.models.CarrierEthernetVirtualConnection.Type;
+
+/**
+ * Carrier Ethernet provisioner of connectivity for forwarding constructs and bandwidth profiles.
+ */
+@Component(immediate = true)
+@Service
+public class MetroNetworkProvisioner implements MetroNetworkProvisionerService {
+
+ private final Logger log = getLogger(getClass());
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected PathService pathService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected TopologyService topologyService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected DeviceService deviceService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected ControlChannelListenerService channelListenerService;
+
+ @Activate
+ protected void activate() {
+ log.info("Started");
+ }
+
+ @Deactivate
+ protected void deactivate() {
+ log.info("Stopped");
+ }
+
+ @Override
+ public void setupConnectivity(CarrierEthernetForwardingConstruct fc) {
+ boolean allPairsConnected = true;
+
+ HashMap<CarrierEthernetNetworkInterface, HashSet<CarrierEthernetNetworkInterface>> ingressEgressNiMap =
+ new HashMap<>();
+
+ // Temporary set for iterating through LTP pairs
+ Set<CarrierEthernetLogicalTerminationPoint> tempLtpSet = new HashSet<>(fc.ltpSet());
+
+ // Temporary set for indicating which LTPs were finally included
+ Set<CarrierEthernetLogicalTerminationPoint> usedLtpSet = new HashSet<>();
+
+ Iterator<CarrierEthernetLogicalTerminationPoint> ltpIt1 = tempLtpSet.iterator();
+ while (ltpIt1.hasNext()) {
+
+ CarrierEthernetLogicalTerminationPoint ltp1 = ltpIt1.next();
+
+ // Iterate through all the remaining NIs
+ Iterator<CarrierEthernetLogicalTerminationPoint> ltpIt2 = tempLtpSet.iterator();
+ while (ltpIt2.hasNext()) {
+
+ CarrierEthernetLogicalTerminationPoint ltp2 = ltpIt2.next();
+
+ // Skip equals
+ if (ltp1.equals(ltp2)) {
+ continue;
+ }
+
+ // Do not establish connectivity between leaf NIs (applies to Rooted_Multipoint)
+ // FIXME: Use proper LTP roles
+ if (ltp1.role().equals(Role.LEAF)
+ && ltp2.role().equals(Role.LEAF)) {
+ continue;
+ }
+
+ // Update the ingress-egress NI map based on the calculated paths
+ if (!updateIngressEgressNiMap(ltp1.ni(), ltp2.ni(), ingressEgressNiMap,
+ fc.congruentPaths(), fc.type())) {
+ allPairsConnected = false;
+ continue;
+ }
+
+ // Indicate that connection for at least one NI pair has been established
+ fc.setState(CarrierEthernetForwardingConstruct.State.ACTIVE);
+
+ // Add NIs to the set of NIs used by the EVC
+ usedLtpSet.add(ltp1);
+ usedLtpSet.add(ltp2);
+ }
+ // Remove NI from temporary set so that each pair is visited only once
+ ltpIt1.remove();
+ }
+
+ // Establish connectivity using the ingressEgressNiMap
+ ingressEgressNiMap.keySet().forEach(srcNi -> {
+ // only the listener that communicates with the domain associated to this fc will
+ // accomplish the request
+ channelListenerService.listeners().forEach(
+ listener -> listener.setNodeForwarding(fc, srcNi, ingressEgressNiMap.get(srcNi))
+ );
+ });
+
+ // Update the NI set, based on the NIs actually used
+ fc.setLtpSet(usedLtpSet);
+
+ if (fc.isActive()) {
+ if (!allPairsConnected) {
+ fc.setState(CarrierEthernetConnection.State.PARTIAL);
+ }
+ }
+ }
+
+ /**
+ * Select feasible link paths between two NIs in both directions and update
+ * ingressEgressNiMap accordingly.
+ *
+ * @param ni1 the first NI
+ * @param ni2 the second NI
+ * @param ingressEgressNiMap the method will add here any ingress-egress NI associations
+ * @param congruentPaths if true indicates that n1->n2 will follow the same path as n2->n1
+ * @return true if the path was updated and false if a path could not be found in any of the directions
+ */
+ private boolean updateIngressEgressNiMap(CarrierEthernetNetworkInterface ni1, CarrierEthernetNetworkInterface ni2,
+ HashMap<CarrierEthernetNetworkInterface,
+ HashSet<CarrierEthernetNetworkInterface>> ingressEgressNiMap,
+ boolean congruentPaths, CarrierEthernetVirtualConnection.Type evcType) {
+
+ // Find the paths for both directions at the same time, so that we can skip the pair if needed
+ List<Link> forwardLinks = generateLinkList(ni1.cp(), ni2.cp(), evcType);
+ List<Link> backwardLinks =
+ congruentPaths ? generateInverseLinkList(forwardLinks) : generateLinkList(ni2.cp(), ni1.cp(), evcType);
+
+ // Skip this UNI pair if no feasible path could be found
+ if (forwardLinks == null || (backwardLinks == null)) {
+ log.warn("There are no feasible paths between {} and {}.",
+ ni1.cp().deviceId(), ni2.cp().deviceId());
+ return false;
+ }
+
+ // Populate the ingress/egress NI map for the forward and backward paths
+ populateIngressEgressNiMap(ni1, ni2, forwardLinks, ingressEgressNiMap);
+ populateIngressEgressNiMap(ni2, ni1, backwardLinks, ingressEgressNiMap);
+
+ return true;
+ }
+
+ private void populateIngressEgressNiMap(CarrierEthernetNetworkInterface srcNi,
+ CarrierEthernetNetworkInterface dstNi,
+ List<Link> linkList,
+ HashMap<CarrierEthernetNetworkInterface,
+ HashSet<CarrierEthernetNetworkInterface>> ingressEgressNiMap
+ ) {
+ // FIXME: Fix the method - avoid generating GENERIC NIs if not needed
+ // Add the src and destination NIs as well as the associated Generic NIs
+ ingressEgressNiMap.putIfAbsent(srcNi, new HashSet<>());
+ // Add last hop entry only if srcNi, dstNi aren't on same device (in which case srcNi, ingressNi would coincide)
+ if (!srcNi.cp().deviceId().equals(dstNi.cp().deviceId())) {
+ // If srcNi, dstNi are not on the same device, create mappings to/from new GENERIC NIs
+ ingressEgressNiMap.get(srcNi).add(new CarrierEthernetGenericNi(linkList.get(1).src(), null));
+ CarrierEthernetGenericNi ingressNi =
+ new CarrierEthernetGenericNi(linkList.get(linkList.size() - 2).dst(), null);
+ ingressEgressNiMap.putIfAbsent(ingressNi, new HashSet<>());
+ ingressEgressNiMap.get(ingressNi).add(dstNi);
+ } else {
+ // If srcNi, dstNi are on the same device, this is the only mapping that will be created
+ ingressEgressNiMap.get(srcNi).add(dstNi);
+ }
+
+ // Go through the links and
+ //
+ // create/add the intermediate NIs
+ for (int i = 1; i < linkList.size() - 2; i++) {
+ CarrierEthernetGenericNi ingressNi = new CarrierEthernetGenericNi(linkList.get(i).dst(), null);
+ ingressEgressNiMap.putIfAbsent(ingressNi, new HashSet<>());
+ ingressEgressNiMap.get(ingressNi).add(new CarrierEthernetGenericNi(linkList.get(i + 1).src(), null));
+ }
+ }
+
+ private List<Link> generateLinkList(ConnectPoint cp1, ConnectPoint cp2,
+ Type evcType) {
+ Set<Path> paths;
+ Path path = null;
+
+ if (!cp1.deviceId().equals(cp2.deviceId())) {
+ // If cp1 and cp2 are not on the same device a path must be found
+ if (evcType.equals(Type.POINT_TO_POINT)) {
+ // For point-to-point connectivity use pre-calculated paths to make sure the shortest paths are chosen
+ paths = pathService.getPaths(cp1.deviceId(), cp2.deviceId());
+ } else {
+ // Recalculate path so that it's over the pre-calculated spanning tree
+ // FIXME: Find a more efficient way (avoid recalculating paths)
+ paths = pathService.getPaths(cp1.deviceId(), cp2.deviceId(),
+ new CarrierEthernetSpanningTreeWeight(topologyService));
+ }
+
+ // Just select any of the returned paths
+ // TODO: Select path in more sophisticated way and return null if any of the constraints cannot be met
+ path = paths.iterator().hasNext() ? paths.iterator().next() : null;
+
+ if (path == null) {
+ return null;
+ }
+ }
+
+ List<Link> links = new ArrayList<>();
+ links.add(createEdgeLink(cp1, true));
+ if (!cp1.deviceId().equals(cp2.deviceId())) {
+ links.addAll(path.links());
+ }
+ links.add(createEdgeLink(cp2, false));
+
+ return links;
+ }
+
+ private List<Link> generateInverseLinkList(List<Link> originalLinks) {
+
+ if (originalLinks == null) {
+ return null;
+ }
+
+ List<Link> inverseLinks = new ArrayList<>();
+
+ inverseLinks.add(createEdgeLink(originalLinks.get(originalLinks.size() - 1).src(), true));
+
+ for (int i = originalLinks.size() - 2; i > 0; i--) {
+ // FIXME: Check again the Link creation parameters
+ inverseLinks.add(DefaultLink.builder()
+ .src(originalLinks.get(i).dst())
+ .dst(originalLinks.get(i).src())
+ .type(Link.Type.DIRECT)
+ .providerId(new ProviderId("none", "none"))
+ .build());
+ }
+ inverseLinks.add(createEdgeLink(originalLinks.get(0).dst(), false));
+
+ return inverseLinks;
+ }
+
+ @Override
+ public void removeConnectivity(CarrierEthernetForwardingConstruct fc) {
+ channelListenerService.listeners()
+ .forEach(listener -> listener.removeAllForwardingResources(fc.id()));
+ }
+
+ @Override
+ public void createBandwidthProfiles(CarrierEthernetForwardingConstruct fc) {
+ fc.uniSet().forEach(uni -> channelListenerService.listeners()
+ .forEach(listener -> listener.createBandwidthProfileResources(fc, uni)));
+ }
+
+ @Override
+ public void applyBandwidthProfiles(CarrierEthernetForwardingConstruct fc) {
+ // TODO: Select node manager depending on device protocol
+ fc.uniSet().forEach(uni -> channelListenerService.listeners()
+ .forEach(listener -> listener.applyBandwidthProfileResources(fc, uni)));
+ }
+
+ @Override
+ public void removeBandwidthProfiles(CarrierEthernetForwardingConstruct fc) {
+ // TODO: Select node manager depending on device protocol
+ fc.ltpSet().forEach((ltp -> {
+ if (ltp.ni().type().equals(CarrierEthernetNetworkInterface.Type.UNI)) {
+ channelListenerService.listeners()
+ .forEach(listener ->
+ listener.removeBandwidthProfileResources(fc, (CarrierEthernetUni) ltp.ni()));
+ }
+ }));
+ }
+}
diff --git a/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/MetroOrchestrationManager.java b/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/MetroOrchestrationManager.java
new file mode 100644
index 0000000..fc118ed
--- /dev/null
+++ b/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/MetroOrchestrationManager.java
@@ -0,0 +1,1327 @@
+/*
+ * Copyright 2017-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.opencord.ce.global.orchestration;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Sets;
+import org.apache.commons.lang3.tuple.Pair;
+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.VlanId;
+import org.onosproject.codec.CodecService;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.Device;
+import org.onosproject.net.Link;
+import org.onosproject.net.Path;
+import org.onosproject.net.Port;
+import org.onosproject.net.config.ConfigFactory;
+import org.onosproject.net.config.NetworkConfigEvent;
+import org.onosproject.net.config.NetworkConfigListener;
+import org.onosproject.net.config.NetworkConfigRegistry;
+import org.onosproject.net.config.NetworkConfigService;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.link.LinkService;
+import org.onosproject.net.topology.PathService;
+import org.onosproject.net.topology.TopologyService;
+import org.opencord.ce.api.models.CarrierEthernetBandwidthProfile;
+import org.opencord.ce.api.models.CarrierEthernetEnni;
+import org.opencord.ce.api.models.CarrierEthernetForwardingConstruct;
+import org.opencord.ce.api.models.CarrierEthernetInni;
+import org.opencord.ce.api.models.CarrierEthernetLogicalTerminationPoint;
+import org.opencord.ce.api.models.CarrierEthernetNetworkInterface;
+import org.opencord.ce.api.models.CarrierEthernetSpanningTreeWeight;
+import org.opencord.ce.api.models.CarrierEthernetUni;
+import org.opencord.ce.api.models.CarrierEthernetVirtualConnection;
+import org.opencord.ce.api.models.EvcConnId;
+import org.opencord.ce.api.models.PortVlanConfig;
+import org.opencord.ce.api.services.MetroNetworkProvisionerService;
+import org.opencord.ce.api.services.MetroOrchestrationService;
+import org.slf4j.Logger;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Collectors;
+
+import static org.onosproject.net.DefaultEdgeLink.createEdgeLink;
+import static org.opencord.ce.api.models.CarrierEthernetLogicalTerminationPoint.Role;
+import static org.opencord.ce.api.models.CarrierEthernetVirtualConnection.Type;
+import static org.onosproject.net.config.basics.SubjectFactories.CONNECT_POINT_SUBJECT_FACTORY;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Global orchestration component.
+ */
+@Component(immediate = true)
+@Service
+public class MetroOrchestrationManager implements MetroOrchestrationService {
+ private final Logger log = getLogger(getClass());
+ private static final String APP_NAME = "org.opencord.ce.global.orchestration";
+ private ApplicationId appId;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected LinkService linkService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected DeviceService deviceService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected PathService pathService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected TopologyService topologyService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected NetworkConfigService networkConfigService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected NetworkConfigRegistry cfgRegistry;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected CoreService coreService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected CodecService codecService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected MetroNetworkProvisionerService networkProvisionerService;
+
+
+ // Keeps track of the next S-VLAN tag the app will try to use
+ private static short nextVlanId = 1;
+
+ // Keeps track of the next EVC id the app will try to use
+ // TODO: Use Identifier class instead
+ private static short nextEvcShortId = 1;
+
+ private boolean evcFragmentationEnabled = false;
+ private boolean prevEvcFragmentationStatus = evcFragmentationEnabled;
+
+ // TODO: Implement distributed store for EVCs
+ // The installed EVCs
+ private final Map<EvcConnId, CarrierEthernetVirtualConnection> evcMap = new ConcurrentHashMap<>();
+
+ // TODO: Implement distributed store for Forwarding Constructs
+ // The installed Forwarding Constructs
+ private final Map<EvcConnId, CarrierEthernetForwardingConstruct> fcMap = new ConcurrentHashMap<>();
+
+ // TODO: Implement distributed store for CE UNIs
+ // The installed CE UNIs
+ private final Map<String, CarrierEthernetUni> uniMap = new ConcurrentHashMap<>();
+ private final Set<String> removedUniSet = Sets.newConcurrentHashSet();
+
+ // TODO: Implement distributed store for CE LTPs
+ // The installed CE LTPs
+ private final Map<String, CarrierEthernetLogicalTerminationPoint> ltpMap = new ConcurrentHashMap<>();
+
+ // The LTP ids that have been explicitly removed (or requested to be removed) from the global LTP map
+ private final Set<String> removedLtpSet = Sets.newConcurrentHashSet();
+
+ private final List<ConfigFactory<?, ?>> factories = ImmutableList.of(
+ new ConfigFactory<ConnectPoint, PortVlanConfig>(CONNECT_POINT_SUBJECT_FACTORY,
+ PortVlanConfig.class, PortVlanConfig.CONFIG_KEY) {
+ @Override
+ public PortVlanConfig createConfig() {
+ return new PortVlanConfig();
+ }
+ });
+
+ // Map of connect points and corresponding VLAN tag
+ private final Map<ConnectPoint, VlanId> portVlanMap = new ConcurrentHashMap<>();
+
+ private NetworkConfigListener netcfgListener = new InternalNetworkConfigListener();
+
+ /**
+ * Activate this component.
+ */
+ @Activate
+ public void activate() {
+ appId = coreService.registerApplication(APP_NAME);
+ networkConfigService.addListener(netcfgListener);
+ factories.forEach(cfgRegistry::registerConfigFactory);
+ }
+
+ /**
+ * Deactivate this component.
+ */
+ @Deactivate
+ public void deactivate() {
+ networkConfigService.removeListener(netcfgListener);
+ factories.forEach(cfgRegistry::unregisterConfigFactory);
+ removeAllEvcs();
+ removeAllFcs();
+ }
+
+ @Override
+ public Map<EvcConnId, CarrierEthernetVirtualConnection> evcMap() {
+ return this.evcMap;
+ }
+
+ @Override
+ public CarrierEthernetVirtualConnection getEvc(EvcConnId evcId) {
+ return evcMap.get(evcId);
+ }
+
+ @Override
+ public CarrierEthernetForwardingConstruct getFc(EvcConnId fcId) {
+ return fcMap.get(fcId);
+ }
+
+ @Override
+ public Map<EvcConnId, CarrierEthernetForwardingConstruct> fcMap() {
+ return fcMap;
+ }
+
+ @Override
+ public Map<String, CarrierEthernetLogicalTerminationPoint> ltpMap() {
+ return ltpMap;
+ }
+
+ @Override
+ public Map<String, CarrierEthernetUni> getUniMap() {
+ return uniMap;
+ }
+
+ /**
+ * Verify the validity of an EVC representation taking also into account current network status.
+ *
+ * @param originalEvc the provided EVC representation
+ * @return a valid, potentially modified EVC representation, or null if the EVC could not be validated
+ */
+ private CarrierEthernetVirtualConnection validateEvc(CarrierEthernetVirtualConnection originalEvc) {
+
+ // Make a copy of the provided EVC, since it may be modified
+ CarrierEthernetVirtualConnection evc = originalEvc;
+
+ // Try to set a unique numerical id for the EVC unless the EVC is being updated
+ // FIXME: Check again the EVC update case
+ evc.setShortId(generateEvcShortId());
+ if (evc.shortId() == null) {
+ log.error("No available EVC id found.");
+ return null;
+ }
+
+ // Generate and set unique FC id
+ evc.setId(EvcConnId.of(generateEvcId(evc)));
+
+ // Verify that CE-VLAN ID is provided to either all UNIs or none
+ // and set the virtualEvc flag accordingly
+ // Note: Checking also that all NIs are UNIs
+ boolean isVirtual = false;
+ Iterator<CarrierEthernetUni> it = evc.uniSet().iterator();
+ while (it.hasNext()) {
+ CarrierEthernetUni ni = it.next();
+ if (ni.ceVlanId() == VlanId.NONE && isVirtual) {
+ log.error("Could not validate the virtual status of the EVC.");
+ return null;
+ } else if (ni.ceVlanId() != VlanId.NONE) {
+ isVirtual = true;
+ }
+ }
+ evc.setIsVirtual(isVirtual);
+
+ // Set unique id for the EVC unless the EVC is being updated
+ if (evc.id() == null) {
+ evc.setId(EvcConnId.of(generateEvcId(evc)));
+ }
+
+ Set<CarrierEthernetUni> validatedUniSet = new HashSet<>();
+
+ // TODO: Refactor according to the validateFc method
+ // Note: Cannot use the validateFc method here,
+ // because FCs can also be standalone
+
+ // Check the UNIs of the EVC, possibly removing UNIs that are
+ // incompatible with existing global ones
+ it = evc.uniSet().iterator();
+ while (it.hasNext()) {
+ CarrierEthernetUni uni = it.next();
+ // Change the name of the UNI's BWP to the EVC name if it is an EVC BWP
+ if (uni.bwp().type().equals(CarrierEthernetBandwidthProfile.Type.EVC)) {
+ uni.bwp().setId(evc.id().id());
+ }
+ // Check first if corresponding global UNI already exists
+ // by checking against the global UNI Map
+ if (uniMap.keySet().contains(uni.id())) {
+ CarrierEthernetUni existingUni = uniMap.get(uni.id());
+ // Check if the EVC-specific UNI is compatible with the global one
+ if (!(existingUni.validateEcNi(uni))) {
+ // If EVC is of ROOT_MULTIPOINT type and we have removed the root, return null
+ if (evc.type() == Type.ROOT_MULTIPOINT &&
+ uni.role() == CarrierEthernetUni.Role.ROOT) {
+ log.error("Root UNI could not be added to %s EVC.", evc.type().name());
+ return null;
+ }
+ log.warn("UNI {} could not be added to EVC.", uni.id());
+ } else {
+ // Add UNI to EVC
+ validatedUniSet.add(uni);
+ }
+ } else {
+ // Add UNI to EVC
+ validatedUniSet.add(uni);
+ }
+ }
+
+ // Update the EVC UNI set, based on the validated UNIs
+ evc.setUniSet(validatedUniSet);
+
+ // TODO: Check that an ROOT_MULTIPOINT EVC has at most one ROOT
+
+ if (evc.uniSet().size() > evc.maxNumUni()) {
+ log.error("{} EVC can have at most {} UNIs.", evc.maxNumUni());
+ return null;
+ }
+
+ if ((evc.type().equals(Type.ROOT_MULTIPOINT)
+ || evc.type().equals(Type.MULTIPOINT_TO_MULTIPOINT))
+ && (evc.uniSet().size() < 2)) {
+ log.error("{} EVC requires at least two UNIs.", evc.type().name());
+ return null;
+ }
+
+ if (evc.type().equals(Type.POINT_TO_POINT) && (evc.uniSet().size() != 2)) {
+ log.error("{} EVC requires exactly two UNIs.", evc.type().name());
+ return null;
+ }
+
+ return evc;
+ }
+
+ @Override
+ public CarrierEthernetVirtualConnection installEvc(CarrierEthernetVirtualConnection evc) {
+
+ // If EVC already exists, remove it and reestablish with new parameters
+ if (evc.id() != null && evcMap.containsKey(evc.id())) {
+ return updateEvc(evc);
+ } else {
+ // id will be generated during validation below
+ evc.setId(null);
+ }
+
+ if (validateEvc(evc) == null) {
+ log.error("EVC could not be installed, please check log for details.");
+ return null;
+ }
+
+ //////////////////////////////////////////////////////////////////////////////////////////////////
+ // This is the "orchestration" part of the CE app
+ //////////////////////////////////////////////////////////////////////////////////////////////////
+
+ // TODO: Add configurable parameter to determine if fragmentation will take place
+ if (evcFragmentationEnabled) {
+ evc.setFcSet(fragmentEvc(evc));
+ } else {
+ evc.setFcSet(Collections.singleton(fcFromEvc(evc)));
+ }
+ evc.fcSet().forEach(fc -> log.info("DEBUG-EVC: {}", fc.toString()));
+ evc.fcSet().forEach(fc -> fc.ltpSet().forEach(ltp -> log.info("DEBUG-LTP: {}", ltp.toString())));
+
+ //////////////////////////////////////////////////////////////////////////////////////////////////
+
+ // Assign S-TAGs to FCs
+ // If network configuration is there, get tags from corresponding ports
+ // else generate unique tags to be used
+ // FIXME: This was supposed to be done in the validateFc method
+ // FIXME: but we need a vlanId here already, so that S-TAGs can be assigned below among paired INNIs/ENNIs
+ Set<VlanId> excludedVlans = usedVlans();
+ evc.fcSet().forEach(fc -> {
+ Optional<VlanId> cfgVlanId = getCfgVlan(fc);
+ if (cfgVlanId.isPresent()) {
+ fc.setVlanId(cfgVlanId.get());
+ } else {
+ fc.setVlanId(generateVlanId(excludedVlans));
+ }
+ excludedVlans.add(fc.vlanId());
+ });
+
+ // For each INNI/ENNI of each FC, find the paired INNI/ENNI and assign S-TAG according to the other FC's vlanId
+ for (CarrierEthernetForwardingConstruct fc : evc.fcSet()) {
+ for (CarrierEthernetLogicalTerminationPoint ltp : fc.ltpSet()) {
+ if (!ltp.ni().type().equals(CarrierEthernetNetworkInterface.Type.UNI)) {
+ // Find the cp at the other end of the link
+ Link link = linkService.getEgressLinks(ltp.ni().cp()).iterator().next();
+ String ltpId = link.dst().deviceId().toString() + "/" + link.dst().port().toString();
+ // Find the corresponding FC - assuming LTP ids are the same as connect point ids
+ CarrierEthernetForwardingConstruct neighborFc = getFcFromLtpId(ltpId, evc.fcSet());
+ if (neighborFc != null) {
+ if (ltp.ni().type().equals(CarrierEthernetNetworkInterface.Type.INNI)) {
+ ((CarrierEthernetInni) ltp.ni()).setSVlanId(neighborFc.vlanId());
+ } else if (ltp.ni().type().equals(CarrierEthernetNetworkInterface.Type.ENNI)) {
+ ((CarrierEthernetEnni) ltp.ni()).setSVlanId(neighborFc.vlanId());
+ }
+ }
+ }
+ }
+ }
+
+ // Install the constituent FCs
+ evc.fcSet().forEach(fc -> {
+ // Increment the FC refCount
+ fc.refCount().incrementAndGet();
+ installFc(fc);
+ });
+
+ // Update the EVC UNI set based on the LTPs used during FC connectivity
+ Set<CarrierEthernetUni> usedUniSet = new HashSet<>();
+ evc.fcSet().forEach(fc -> usedUniSet.addAll(fc.uniSet()));
+ evc.setUniSet(usedUniSet);
+
+ // Determine EVC state based on the state of the constituent FCs
+ evc.setState(CarrierEthernetVirtualConnection.State.ACTIVE);
+ Iterator<CarrierEthernetForwardingConstruct> fcIt = evc.fcSet().iterator();
+ while (fcIt.hasNext()) {
+ CarrierEthernetForwardingConstruct fc = fcIt.next();
+ evc.setState(CarrierEthernetVirtualConnection.State.valueOf(fc.state().name()));
+ if (!evc.isActive()) {
+ break;
+ }
+ }
+
+ if (evc.isActive()) {
+ // If EVC installation was successful, then register the EVC
+ evcMap.put(evc.id(), evc);
+ } else {
+ // If EVC installation was not successful, then do not register the EVC and rollback FC installations
+ evc.fcSet().forEach(fc -> {
+ // Decrement the FC refCount to make removal possible
+ fc.refCount().decrementAndGet();
+ removeFc(fc.id());
+ });
+ }
+
+ return evc;
+ }
+
+ /**
+ * Creates a single FC out of an EVC.
+ *
+ * @param evc the EVC representation
+ * @return the equivalent FC
+ */
+ private CarrierEthernetForwardingConstruct fcFromEvc(CarrierEthernetVirtualConnection evc) {
+ Set<CarrierEthernetLogicalTerminationPoint> ltpSet = new HashSet<>();
+ evc.uniSet().forEach(uni -> ltpSet.add(new CarrierEthernetLogicalTerminationPoint(null, uni)));
+ return CarrierEthernetForwardingConstruct.builder()
+ .type(evc.type())
+ .ltpSet(ltpSet)
+ .build();
+ }
+
+ /**
+ * Fragments an EVC into multiple FCs.
+ *
+ * @param evc the EVC representation
+ * @return the set of FCs constituting the EVC
+ */
+ private Set<CarrierEthernetForwardingConstruct> fragmentEvc(CarrierEthernetVirtualConnection evc) {
+
+ Set<CarrierEthernetForwardingConstruct> fcSet = new HashSet<>();
+
+ // Each LTP can only belong to a single FC, hence using LTP_id -> LTP_set map
+ Map<String, Set<CarrierEthernetLogicalTerminationPoint>> ltpSetMap = new HashMap<>();
+
+ // Temporary set to browse through all EVC UNI pairs
+ Set<CarrierEthernetUni> tempUniSet = new HashSet<>(evc.uniSet());
+
+ Iterator<CarrierEthernetUni> uniIt1 = tempUniSet.iterator();
+ while (uniIt1.hasNext()) {
+
+ CarrierEthernetUni uni1 = uniIt1.next();
+
+ // Iterate through all the remaining NIs
+ Iterator<CarrierEthernetUni> uniIt2 = tempUniSet.iterator();
+ while (uniIt2.hasNext()) {
+
+ CarrierEthernetUni uni2 = uniIt2.next();
+
+ // Skip equals
+ if (uni1.equals(uni2)) {
+ continue;
+ }
+
+ // Do not establish connectivity between leaf NIs
+ // (applies to Rooted_Multipoint)
+ if (uni1.role().equals(CarrierEthernetUni.Role.LEAF)
+ && uni2.role().equals(CarrierEthernetUni.Role.LEAF)) {
+ continue;
+ }
+
+ // Note: INNIs should always appear in pairs
+ List<Pair<CarrierEthernetLogicalTerminationPoint,
+ CarrierEthernetLogicalTerminationPoint>> ltpPairList
+ = new ArrayList<>();
+
+ // If uni1 and uni2 are on same device, skip path calculation
+ // and directly generate a single LTP pair to be used below
+ if (uni1.cp().deviceId().equals(uni2.cp().deviceId())) {
+ ltpPairList.add(Pair.of(new CarrierEthernetLogicalTerminationPoint(null, uni1),
+ new CarrierEthernetLogicalTerminationPoint(null, uni2)));
+ } else {
+ // Calculate path assuming return paths are the same
+ // TODO: Handle the congruent paths case?
+ Set<Path> paths;
+ if (evc.type().equals(Type.POINT_TO_POINT)) {
+ // For point-to-point connectivity use the pre-calculated paths
+ // to make sure the shortest paths are chosen
+ paths = pathService.getPaths(uni1.cp().deviceId(), uni2.cp().deviceId());
+ } else {
+ // Recalculate path so that it's over the pre-calculated spanning tree
+ // FIXME: Find a more efficient way (avoid recalculating paths)
+ paths = pathService.getPaths(uni1.cp().deviceId(), uni2.cp().deviceId(),
+ new CarrierEthernetSpanningTreeWeight(topologyService));
+ }
+
+ // Just select any of the returned paths
+ // TODO: Select path in more sophisticated way and return null
+ // if any of the constraints cannot be met
+ Path path = paths.iterator().hasNext() ? paths.iterator().next() : null;
+
+ if (path == null) {
+ return null;
+ }
+
+ List<Link> links = new ArrayList<>();
+ links.add(createEdgeLink(uni1.cp(), true));
+ links.addAll(path.links());
+ links.add(createEdgeLink(uni2.cp(), false));
+
+ ////////////////////////////////////////////////////////////
+ // Get LTP pairs of ingress/egress NIs along the link path
+ // (non-LTP connect points are ignored)
+ ////////////////////////////////////////////////////////////
+
+ CarrierEthernetLogicalTerminationPoint srcLtp = null, dstLtp = null;
+ // These are the roles that will be used for all pairs found below
+ Role srcLtpRole, dstLtpRole;
+ // The source in any pair will always have the same role as the LTP from which the paths starts
+ srcLtpRole = Role.valueOf(uni1.role().name());
+ // The destination in any pair will always have the same role as the LTP at which the path ends
+ dstLtpRole = Role.valueOf(uni2.role().name());
+ for (int i = 0; i < links.size(); i++) {
+ // Try to get the destination LTP of a pair
+ if (srcLtp != null && i != 0) {
+ // If this is the last, use existing EVC UNI, else create a new FC LTP and set Role
+ dstLtp = (i == links.size() - 1) ?
+ new CarrierEthernetLogicalTerminationPoint(null, uni2) :
+ fcLtpFromCp(links.get(i).src(), dstLtpRole);
+ }
+ if (dstLtp != null) {
+ // Create a new LTP pair and null the srcLtp
+ // so that we can continue searching for a new pair
+ ltpPairList.add(Pair.of(srcLtp, dstLtp));
+ srcLtp = null;
+ }
+ // Try to get the source LTP of a pair
+ if (srcLtp == null && i != links.size() - 1) {
+ // If this is the first, use existing EVC UNI, else create a new FC LTP and set Role
+ srcLtp = (i == 0) ?
+ new CarrierEthernetLogicalTerminationPoint(null, uni1) :
+ fcLtpFromCp(links.get(i).dst(), srcLtpRole);
+ }
+ }
+ }
+
+ ////////////////////////////////////////////////////////////////
+ // Go through all the LTP pairs found and map each LTP to a set
+ // of LTPs (create it if it doesn't exist)
+ ////////////////////////////////////////////////////////////////
+
+ // Note: Each LTP can only belong to a single set, so each set
+ // will eventually correspond to an FC
+
+ ltpPairList.forEach(ltpPair -> {
+ CarrierEthernetLogicalTerminationPoint ltp1 = ltpPair.getLeft();
+ CarrierEthernetLogicalTerminationPoint ltp2 = ltpPair.getRight();
+ if (ltpSetMap.containsKey(ltp1.id()) && !ltpSetMap.containsKey(ltp2.id())) {
+ // If one of the LTPs is already contained in a set, add the other one as well in that set
+ ltpSetMap.get(ltp1.id()).add(ltp2);
+ ltpSetMap.put(ltp2.id(), ltpSetMap.get(ltp1.id()));
+ } else if (ltpSetMap.containsKey(ltp2.id()) & !ltpSetMap.containsKey(ltp1.id())) {
+ // If one of the LTPs is already contained in a set, add the other one as well in that set
+ ltpSetMap.get(ltp2.id()).add(ltp1);
+ ltpSetMap.put(ltp1.id(), ltpSetMap.get(ltp2.id()));
+ } else if (!ltpSetMap.containsKey(ltp1.id()) && !ltpSetMap.containsKey(ltp2.id())) {
+ // Create a new LTP set containing the two LTPs and map both to it
+ ltpSetMap.put(ltp1.id(), Sets.newHashSet(ltp1, ltp2));
+ ltpSetMap.put(ltp2.id(), ltpSetMap.get(ltp1.id()));
+ }
+ });
+ }
+ // Remove UNI from temporary set so that each pair is visited only once
+ uniIt1.remove();
+ }
+
+ //////////////////////////////////////////////////////////////////////////////////
+ // Go through all unique LTP sets generated above and create the corresponding FCs
+ //////////////////////////////////////////////////////////////////////////////////
+
+ new HashSet<>(ltpSetMap.values()).forEach(ltpSet -> {
+ CarrierEthernetForwardingConstruct.Builder fcBuilder =
+ CarrierEthernetForwardingConstruct.builder().ltpSet(ltpSet);
+ // Type is determined by number and type of LTPs in each set
+ Type fcType =
+ ltpSet.size() == 2 ? Type.POINT_TO_POINT
+ : Type.MULTIPOINT_TO_MULTIPOINT;
+ // If one of the LTPs is LEAF, indicate FC as ROOT_MULTIPOINT
+ for (CarrierEthernetLogicalTerminationPoint ltp : ltpSet) {
+ if (ltp.role().equals(Role.LEAF)) {
+ fcType = Type.ROOT_MULTIPOINT;
+ break;
+ }
+ }
+ fcSet.add(fcBuilder.type(fcType).build());
+ log.info("Created ForwardingConstruct comprising LogicalTerminationPoints {}",
+ ltpSet.stream()
+ .map(CarrierEthernetLogicalTerminationPoint::id)
+ .collect(Collectors.toList()));
+ });
+
+ return fcSet;
+ }
+
+ @Override
+ public CarrierEthernetVirtualConnection updateEvc(CarrierEthernetVirtualConnection evc) {
+ // Just checking again
+ if (evcMap.containsKey(evc.id())) {
+ log.info("Updating existing EVC {}", evc.id());
+ removeEvc(evc.id());
+ }
+ return installEvc(evc);
+ }
+
+ /**
+ * Applies FC- specific LTP attributes to global LTPs or adds them to the global LTP map if not there.
+ *
+ * @param ltpSet set of FC-specific LTPs the attributes of which will be applied to the global LTPs
+ */
+ private void applyFcToGlobalLtps(Set<CarrierEthernetLogicalTerminationPoint> ltpSet) {
+ ltpSet.forEach(ltp -> {
+ if (!(ltpMap.keySet().contains(ltp.id()))) {
+ // Just add the LTP as it appears at the FC
+ addGlobalLtp(ltp);
+ } else {
+ // Add LTP resources (BWP, CE-VLAN ID, S-TAG) to existing global LTP
+ ltpMap.get(ltp.id()).ni().addEcNi(ltp.ni());
+ // Update config identifier
+ ltpMap.get(ltp.id()).ni().setCfgId(ltp.ni().cfgId());
+ }
+ });
+ }
+
+ /**
+ * Removes bandwidth profiles from the UNIs of an FC.
+ *
+ * @param fc the FC representation
+ */
+ // TODO: Remove LTPs if needed from the global LTP/UNI map
+ private void removeFcFromGlobalLtps(CarrierEthernetForwardingConstruct fc) {
+ // TODO: Check if the bandwidth profile really needs to be removed (e.g. may be CoS)
+ //// ceProvisioner.removeBandwidthProfiles(fc);
+ // Remove LTP resources (BWP, CE-VLAN ID, S-TAG) from corresponding global LTPs
+ fc.ltpSet().forEach(ltp -> ltpMap.get(ltp.id()).ni().removeEcNi(ltp.ni()));
+ }
+
+ @Override
+ public void removeAllEvcs() {
+ evcMap.keySet().forEach(this::removeEvc);
+ }
+
+ @Override
+ public void removeEvc(EvcConnId evcId) {
+ if (evcMap.containsKey(evcId)) {
+ CarrierEthernetVirtualConnection evc = evcMap.get(evcId);
+ evc.fcSet().forEach(fc -> {
+ // Decrement the FC refCount to make removal possible
+ fc.refCount().decrementAndGet();
+ removeFc(fc.id());
+ });
+ // Avoid excessively incrementing EVC ids
+ nextEvcShortId = evc.shortId() < nextEvcShortId ? evc.shortId() : nextEvcShortId;
+ evcMap.remove(evcId);
+ }
+ }
+
+ /**
+ * Verify the validity of an FC representation taking also into account current network status.
+ *
+ * @param fc the provided FC representation
+ * @return a valid, potentially modified FC representation, or null if the FC could not be validated
+ */
+ private CarrierEthernetForwardingConstruct validateFc(CarrierEthernetForwardingConstruct fc) {
+
+ // Try to set a unique VLAN id for the FC unless the EVC is being updated
+ // TODO: Add different connectivity types
+ // FIXME: This is an extra check to be able to generate/set VLAN id for FC before calling installFc
+ if (fc.vlanId() == null) {
+ fc.setVlanId(generateVlanId(usedVlans()));
+ }
+ if (fc.vlanId() == null) {
+ log.error("No available VLAN id found.");
+ return null;
+ }
+
+ // Generate and set unique FC id
+ fc.setId(EvcConnId.of(generateFcId(fc)));
+
+ Set<CarrierEthernetLogicalTerminationPoint> validatedLtpSet = new HashSet<>();
+
+ // Check the NIs of the FC, possibly removing NIs that are incompatible with existing ones
+ Iterator<CarrierEthernetLogicalTerminationPoint> ltpIt = fc.ltpSet().iterator();
+ while (ltpIt.hasNext()) {
+ CarrierEthernetLogicalTerminationPoint ltp = ltpIt.next();
+ boolean ltpValidated = true;
+ if (ltp.type().equals(CarrierEthernetNetworkInterface.Type.UNI)) {
+ CarrierEthernetUni uni = (CarrierEthernetUni) ltp.ni();
+ // Change the name of the UNI's BWP to the FC name if it is an EVC BWP
+ if (uni.bwp().type().equals(CarrierEthernetBandwidthProfile.Type.EVC)) {
+ // FIXME: Find a way to use the EVC name instead
+ uni.bwp().setId(fc.id().id());
+ }
+ }
+ // Check first if LTP already exists by checking against the global LTP Map
+ if (ltpMap.keySet().contains(ltp.id())) {
+ CarrierEthernetNetworkInterface existingNi = ltpMap.get(ltp.id()).ni();
+ // Check if the FC-specific NI is compatible with the global one
+ if (!(existingNi.validateEcNi(ltp.ni()))) {
+ ltpValidated = false;
+ }
+ }
+ if (!ltpValidated) {
+ // If EVC is of ROOT_MULTIPOINT type and we have removed the root, return null
+ if (fc.type() == CarrierEthernetForwardingConstruct.Type.ROOT_MULTIPOINT &&
+ ltp.role() == Role.ROOT) {
+ log.error("Root LTP could not be added to %s FC.", fc.type().name());
+ return null;
+ }
+ log.warn("LTP {} could not be added to FC.", ltp.id());
+ continue;
+ } else {
+ // Add LTP to FC description
+ validatedLtpSet.add(ltp);
+ }
+ }
+
+ fc.setLtpSet(validatedLtpSet);
+
+ return fc;
+ }
+
+ @Override
+ public CarrierEthernetForwardingConstruct installFc(CarrierEthernetForwardingConstruct fc) {
+
+ // If FC already exists, remove it and reestablish with new parameters
+ if (fc.id() != null && fcMap.containsKey(fc.id())) {
+ return updateFc(fc);
+ } else {
+ fc.setId(null);
+ }
+
+ if (validateFc(fc) == null) {
+ log.error("FC could not be installed, please check log for details.");
+ return null;
+ }
+
+ // Create BW profiles first so that they will be available if needed during the connectivity phase
+ networkProvisionerService.createBandwidthProfiles(fc);
+
+ networkProvisionerService.setupConnectivity(fc);
+
+
+ // If connectivity was not successful, then do not register the FC and do not apply BW profiles
+ // If not, the BW profiles that were created earlier need to be removed
+ if (fc.state().equals(CarrierEthernetForwardingConstruct.State.ACTIVE)) {
+ // Apply BWP-related resources (e.g. Meters) to the packet switches
+ networkProvisionerService.applyBandwidthProfiles(fc);
+ // Apply the BWPs of the FC UNIs to the global UNIs, creating them if needed
+ //applyEvcToGlobalUnis(fc.uniSet());
+ applyFcToGlobalLtps(fc.ltpSet());
+ // Increment the global LTP and corresponding NI refCount
+ fc.ltpSet().forEach(ltp -> ltpMap.get(ltp.id()).refCount().incrementAndGet());
+ fcMap.put(fc.id(), fc);
+ } else {
+ networkProvisionerService.removeBandwidthProfiles(fc);
+ }
+
+ return fc;
+ }
+
+ @Override
+ public CarrierEthernetForwardingConstruct updateFc(CarrierEthernetForwardingConstruct fc) {
+ // Just checking again
+ if (fcMap.containsKey(fc.id())) {
+ log.info("Updating existing FC {}", fc.id());
+ // Keep the VLAN ID of the original FC
+ fc.setVlanId(fcMap.get(fc.id()).vlanId());
+ // FIXME: Currently FC update only possible for standalone FCs
+ removeFc(fc.id());
+ }
+ return installFc(fc);
+ }
+
+ @Override
+ public void removeAllFcs() {
+ fcMap.keySet().forEach(fcId -> removeFc(fcId));
+ }
+
+ @Override
+ public CarrierEthernetForwardingConstruct removeFc(EvcConnId fcId) {
+ if (fcMap.containsKey(fcId)) {
+ CarrierEthernetForwardingConstruct fc = fcMap.get(fcId);
+ if (fc.refCount().get() != 0) {
+ log.warn("Could not remove FC {}: RefCount is not zero", fc.id());
+ return null;
+ }
+ networkProvisionerService.removeConnectivity(fc);
+ networkProvisionerService.removeBandwidthProfiles(fc);
+ removeFcFromGlobalLtps(fc);
+ // Avoid excessively incrementing FC VLAN ids
+ nextVlanId = (fcMap.get(fcId).vlanId().toShort() < nextVlanId ?
+ fcMap.get(fcId).vlanId().toShort() :
+ nextVlanId);
+ // Decrement the global LTP and corresponding NI refCount
+ fcMap.get(fcId).ltpSet().forEach(ltp -> ltpMap.get(ltp.id()).refCount().decrementAndGet());
+ fcMap.remove(fcId);
+ return fc;
+ }
+ return null;
+ }
+
+ /**
+ * Returns the unique S-TAGs currently used by FCs across the CE network.
+ *
+ * @return the S-TAGs currently used
+ */
+ private Set<VlanId> usedVlans() {
+ return fcMap.values().stream().map(CarrierEthernetForwardingConstruct::vlanId)
+ .collect(Collectors.toSet());
+ }
+
+ /**
+ * Generates a new vlanId excluding the provided ones.
+ *
+ * @param excludedVlans the vlanIds that are not allowed
+ * @return the generated vlanId; null if none found
+ */
+ private VlanId generateVlanId(Set<VlanId> excludedVlans) {
+ // If all vlanIds are being used return null, else try to find the next available one
+ if (excludedVlans.size() < VlanId.MAX_VLAN - 1) {
+ while (excludedVlans.contains(VlanId.vlanId(nextVlanId))) {
+ // Get next valid short
+ nextVlanId = (nextVlanId >= VlanId.MAX_VLAN || nextVlanId <= 0 ?
+ 1 : (short) (nextVlanId + 1));
+ }
+ }
+ return excludedVlans.contains(VlanId.vlanId(nextVlanId)) ?
+ null : VlanId.vlanId(nextVlanId);
+ }
+
+ /**
+ * Generates a unique vlanId in the context of the CE app.
+ *
+ * @return the generated vlanId or null if none found
+ */
+ private Short generateEvcShortId() {
+
+ List<Short> evcShortIdList = evcMap.values()
+ .stream()
+ .map(evc -> evc.shortId())
+ .collect(Collectors.toList());
+
+ // If all vlanIds are being used return null, else try to find the next available one
+ if (evcShortIdList.size() < Short.MAX_VALUE - 1) {
+ while (evcShortIdList.contains(nextEvcShortId)) {
+ // Get next valid short
+ nextEvcShortId =
+ (nextEvcShortId >= Short.MAX_VALUE || nextEvcShortId <= 0 ? 1 : (short) (nextEvcShortId + 1));
+ }
+ }
+
+ return evcShortIdList.contains(nextEvcShortId) ? null : nextEvcShortId;
+ }
+
+ /**
+ * Generates a unique EVC id in the context of the CE app.
+ *
+ * @param evc the EVC representation
+ * @return the generated EVC id or null if none found
+ */
+ private String generateEvcId(CarrierEthernetVirtualConnection evc) {
+
+ // TODO: Add different connectivity types
+
+ String tmpType;
+
+ if (evc.type().equals(Type.POINT_TO_POINT)) {
+ tmpType = "Line";
+ } else if (evc.type().equals(Type.MULTIPOINT_TO_MULTIPOINT)) {
+ tmpType = "LAN";
+ } else {
+ tmpType = "Tree";
+ }
+
+ return "E" + (evc.isVirtual() ? "V" : "") + "P-" + tmpType + "-" +
+ evc.shortId().toString();
+ }
+
+ /**
+ * Generates a unique FC id in the context of the CE app.
+ *
+ * @param fc the FC representation
+ * @return the generated FC id or null if none found
+ */
+ private String generateFcId(CarrierEthernetForwardingConstruct fc) {
+
+ // TODO: Add different connectivity types
+
+ return "FC-" + fc.vlanId().toString();
+ }
+
+ @Override
+ public CarrierEthernetLogicalTerminationPoint removeGlobalLtp(String ltpId) {
+
+ if (!ltpMap.containsKey(ltpId)) {
+ log.warn("Could not remove LTP {}: Does not exist", ltpId);
+ return null;
+ }
+
+ if (ltpMap.get(ltpId).refCount().get() != 0) {
+ log.warn("Could not remove LTP {}: RefCount is not zero", ltpId);
+ return null;
+ }
+
+ // Remove LTP from ltpMap and (if needed) UNI from uniMap
+ CarrierEthernetLogicalTerminationPoint ltp = ltpMap.remove(ltpId);
+ // Add LTP to removed set
+ removedLtpSet.add(ltpId);
+ if (ltp.ni().type().equals(CarrierEthernetNetworkInterface.Type.UNI)) {
+ removeGlobalUni(ltp.ni().id());
+ // Add UNI to removed set
+ // TODO: Check if this is right
+ removedUniSet.add(ltp.ni().id());
+ }
+
+ // Find cp at other end of link and try to remove both LTPs - assuming LTP ids are the same as connect point ids
+ if (ltp.ni().type().equals(CarrierEthernetNetworkInterface.Type.INNI)) {
+ Link link = linkService.getEgressLinks(ltp.ni().cp()).iterator().next();
+ String pairLtpId = link.dst().deviceId().toString() + "/" + link.dst().port().toString();
+ ltpMap.remove(pairLtpId);
+ // Add LTP to removed set
+ removedLtpSet.add(pairLtpId);
+ }
+
+ return ltp;
+ }
+
+ @Override
+ public CarrierEthernetUni removeGlobalUni(String uniId) {
+
+ if (!uniMap.containsKey(uniId)) {
+ log.warn("Could not remove UNI {}: Does not exist", uniId);
+ return null;
+ }
+ if (uniMap.get(uniId).refCount().get() != 0) {
+ log.warn("Could not remove UNI {}: RefCount is not zero", uniId);
+ return null;
+ }
+
+ // Remove UNI from uniMap and corresponding LTP (if any) from ltpMp
+ CarrierEthernetUni uni = uniMap.remove(uniId);
+ // FIXME: For now, find LTP assuming ltpId is the same as uniId
+ // Note: If refCount for UNI is not zero, then it should be for the corresponding LTP as well
+ ltpMap.remove(uniId);
+
+ // Add UNI and LTP to removed set
+ removedUniSet.add(uniId);
+ removedLtpSet.add(uniId);
+
+ return uni;
+ }
+
+ @Override
+ public Set<CarrierEthernetUni> getUnisFromTopo(boolean excludeAdded, boolean includeRemoved) {
+
+ CarrierEthernetUni uni;
+ Set<CarrierEthernetUni> uniSet = new HashSet<>();
+ // Generate the device ID/port number identifiers
+ for (Device device : deviceService.getDevices()) {
+ for (Port port : deviceService.getPorts(device.id())) {
+ if (!port.number().isLogical()) {
+ String cpString = device.id().toString() + "/" + port.number();
+ ConnectPoint cp = ConnectPoint.deviceConnectPoint(cpString);
+ uni = generateUni(cp);
+ // Check if UNI was generated and whether it's currently removed
+ if (uni != null
+ && (includeRemoved || !removedUniSet.contains(uni.id()))
+ && (!excludeAdded || !uniMap.containsKey(uni.id()))) {
+ uniSet.add(uni);
+ }
+ }
+ }
+ }
+ return uniSet;
+ }
+
+ @Override
+ public CarrierEthernetUni generateUni(ConnectPoint cp) {
+
+ String uniId = cp.deviceId().toString() + "/" + cp.port().toString();
+
+ if (deviceService.getDevice(cp.deviceId()) == null) {
+ log.error("Could not generate UNI {}: Invalid deviceId {}", uniId, cp.deviceId());
+ return null;
+ }
+ if (deviceService.getPort(cp.deviceId(), cp.port()) == null) {
+ log.error("Could not generate UNI {}: Invalid port {} at device {}", uniId, cp.port(), cp.deviceId());
+ return null;
+ }
+ if (!deviceService.getDevice(cp.deviceId()).type().equals(Device.Type.SWITCH)) {
+ log.debug("Could not generate UNI {}: Device {} is not a switch", uniId, cp.deviceId());
+ return null;
+ }
+
+ Port port = deviceService.getPort(cp.deviceId(), cp.port());
+
+ if (!port.isEnabled()) {
+ log.debug("Could not generate UNI {}: Port {} is not enabled", uniId, port.number().toString());
+ return null;
+ }
+
+ if (validateLtpType(cp, CarrierEthernetNetworkInterface.Type.UNI) == null) {
+ return null;
+ }
+
+ return CarrierEthernetUni.builder()
+ .cp(cp)
+ .cfgId(uniId)
+ .build();
+ }
+
+ @Override
+ public CarrierEthernetUni addGlobalUni(CarrierEthernetUni uni) {
+ // Add UNI only if it's not already there. If corresponding LTP already exists, link them, otherwise create it
+ if (!uniMap.containsKey(uni.id())) {
+ // Add LTP only if it's not already there
+ // FIXME: Assumes LTP and UNI id are the same
+ if (!ltpMap.containsKey(uni.id())) {
+ ltpMap.put(uni.id(), new CarrierEthernetLogicalTerminationPoint(uni.id(), uni));
+ // Remove LTP from deleted set
+ removedLtpSet.remove(uni.id());
+ }
+ uniMap.put(uni.id(), uni);
+ // Remove UNI from deleted set
+ removedUniSet.remove(uni.id());
+ return uni;
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public Set<CarrierEthernetLogicalTerminationPoint> getLtpsFromTopo(boolean excludeAdded, boolean includeRemoved) {
+
+ CarrierEthernetLogicalTerminationPoint ltp;
+ Set<CarrierEthernetLogicalTerminationPoint> ltpSet = new HashSet<>();
+ // Generate the device ID/port number identifiers
+ for (Device device : deviceService.getDevices()) {
+ for (Port port : deviceService.getPorts(device.id())) {
+ if (!port.number().isLogical()) {
+ String cpString = device.id().toString() + "/" + port.number();
+ ConnectPoint cp = ConnectPoint.deviceConnectPoint(cpString);
+ ltp = generateLtp(cp, null);
+ // Check if LTP was generated and whether it's currently removed
+ if (ltp != null
+ && (includeRemoved || !removedLtpSet.contains(ltp.id()))
+ && (!excludeAdded || !ltpMap.containsKey(ltp.id()))) {
+ // Check additionally if associated UNI is currently removed
+ if (!(ltp.ni() instanceof CarrierEthernetUni) || !removedUniSet.contains(ltp.ni().id())) {
+ ltpSet.add(ltp);
+ }
+ }
+ }
+ }
+ }
+ return ltpSet;
+ }
+
+ @Override
+ public CarrierEthernetLogicalTerminationPoint generateLtp(ConnectPoint cp,
+ CarrierEthernetNetworkInterface.Type ltpType) {
+
+ String ltpId = cp.deviceId().toString() + "/" + cp.port().toString();
+
+ if (deviceService.getDevice(cp.deviceId()) == null) {
+ log.error("Could not generate LTP {}: Invalid deviceId {}", ltpId, cp.deviceId());
+ return null;
+ }
+ if (deviceService.getPort(cp.deviceId(), cp.port()) == null) {
+ log.error("Could not generate LTP {}: Invalid port {} at device {}", ltpId, cp.port(), cp.deviceId());
+ return null;
+ }
+ if (!deviceService.getDevice(cp.deviceId()).type().equals(Device.Type.SWITCH)) {
+ log.debug("Could not generate LTP {}: Device {} is not a switch", ltpId, cp.deviceId());
+ return null;
+ }
+
+ Port port = deviceService.getPort(cp.deviceId(), cp.port());
+
+ if (!port.isEnabled()) {
+ log.debug("Could not generate LTP {}: Port {} is not enabled", ltpId, port.number().toString());
+ return null;
+ }
+
+ ltpType = validateLtpType(cp, ltpType);
+
+ if (ltpType == null) {
+ log.warn("Could not generate LTP {}: Type could not be validated", ltpId, port.number().toString());
+ return null;
+ }
+
+ return new CarrierEthernetLogicalTerminationPoint(cp, ltpId, ltpType, null);
+ }
+
+ /**
+ * Validates whether the provided connect point can be associated with an LTP of the provided type.
+ *
+ * Conditions for validating the LTP type:
+ * - If UNI: ConnectPoint is not associated with any link
+ * - If INNI/ENNI: ConnectPoint is associated with a link
+ *
+ * @param cp the connect point associated with the LTP to be validated
+ * @param ltpType the type of the LTP to be validated or null in case a type is to be decided by the method
+ * @return the ltpType if validation succeeded, a new type depending on cp and topo, or null if validation failed
+ */
+ private CarrierEthernetNetworkInterface.Type validateLtpType(
+ ConnectPoint cp, CarrierEthernetNetworkInterface.Type ltpType) {
+ if (linkService.getEgressLinks(cp).isEmpty() && linkService.getIngressLinks(cp).isEmpty()) {
+ // A connect point can be a UNI only if it doesn't belong to any link
+ if (ltpType == null) {
+ // If provided type is null, decide about the LTP type based on connectivity
+ return CarrierEthernetNetworkInterface.Type.UNI;
+ } else if (ltpType.equals(CarrierEthernetNetworkInterface.Type.UNI)) {
+ // Validate type
+ return ltpType;
+ } else {
+ return null;
+ }
+ } else {
+ // A connect point can be an INNI or ENNI only if it belongs to a link
+ if (ltpType == null) {
+ // If provided type is null, decide about the LTP type based on connectivity
+ return CarrierEthernetNetworkInterface.Type.INNI;
+ } else if (ltpType.equals(CarrierEthernetNetworkInterface.Type.INNI) ||
+ ltpType.equals(CarrierEthernetNetworkInterface.Type.ENNI)) {
+ // Validate type
+ return ltpType;
+ } else {
+ return null;
+ }
+ }
+ }
+
+ @Override
+ public CarrierEthernetLogicalTerminationPoint addGlobalLtp(CarrierEthernetLogicalTerminationPoint ltp) {
+ // If LTP contains a UNI, add it only if it's not already there, else point to the existing UNI
+ // FIXME: Assumes LTP and UNI id are the same
+ if (ltp.ni() != null &&
+ ltp.ni().type().equals(CarrierEthernetNetworkInterface.Type.UNI)) {
+
+ if (!uniMap.containsKey(ltp.ni().id())) {
+ uniMap.put(ltp.ni().id(), (CarrierEthernetUni) ltp.ni());
+ // Remove UNI from deleted set
+ removedUniSet.remove(ltp.id());
+ } else {
+ ltp.setNi(uniMap.get(ltp.ni().id()));
+ }
+ }
+ // Add LTP only if it's not already there
+ if (!ltpMap.containsKey(ltp.id())) {
+ // Try to create and add INNI LTP at other end of link as well
+ if (ltp.ni().type().equals(CarrierEthernetNetworkInterface.Type.INNI)) {
+ Link link = linkService.getEgressLinks(ltp.ni().cp()).iterator().next();
+ CarrierEthernetLogicalTerminationPoint pairLtp =
+ generateLtp(link.dst(), CarrierEthernetNetworkInterface.Type.INNI);
+ if (pairLtp == null) {
+ return null;
+ }
+ if (!ltpMap.containsKey(pairLtp.id())) {
+ ltpMap.put(pairLtp.id(), pairLtp);
+ } else {
+ return null;
+ }
+ }
+ ltpMap.put(ltp.id(), ltp);
+ // Remove LTP from deleted set
+ removedLtpSet.remove(ltp.id());
+ return ltp;
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Utility method to obtain an FC-specific LTP (UNI/INNI or ENNI) associated with a connect point.
+ *
+ * @param cp the connect point to check
+ * @return a new FC-specific LTP associated with cp if the corresponding global LTP exists or null otherwise
+ */
+ private CarrierEthernetLogicalTerminationPoint fcLtpFromCp(ConnectPoint cp,
+ Role ltpRole) {
+ // Check first if cp is associated with a device
+ if (cp.deviceId() == null) {
+ return null;
+ }
+ // Assuming LTP id is the same as the connect point id
+ String cpId = cp.deviceId().toString() + "/" + cp.port().toString();
+ if (ltpMap.containsKey(cpId)) {
+ return new CarrierEthernetLogicalTerminationPoint(cp, cpId,
+ ltpMap.get(cpId).type(), ltpRole);
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Utility method to obtain the first FC in a set which contains the LTP with the provided id.
+ *
+ * @param ltpId the LTP id to search
+ * @param fcSet the FC set to search
+ * @return the first FC found in fcSet which contains an LTP with id ltpId, or null if no such FC is found
+ */
+ // FIXME: Find more efficient way to do that
+ private CarrierEthernetForwardingConstruct getFcFromLtpId(String ltpId,
+ Set<CarrierEthernetForwardingConstruct> fcSet) {
+ // Get the first FC that contains the LTP with the provided id
+ for (CarrierEthernetForwardingConstruct fc : fcSet) {
+ if (!fc.ltpSet().stream().filter(ltp -> ltp.id().equals(ltpId)).collect(Collectors.toList()).isEmpty()) {
+ return fc;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public void setEvcFragmentation(boolean evcFragmentationEnabled) {
+ prevEvcFragmentationStatus = this.evcFragmentationEnabled;
+ this.evcFragmentationEnabled = evcFragmentationEnabled;
+ }
+
+ @Override
+ public boolean getEvcFragmentation() {
+ return evcFragmentationEnabled;
+ }
+
+ @Override
+ public void resetEvcFragmentation() {
+ this.evcFragmentationEnabled = prevEvcFragmentationStatus;
+ }
+
+ /**
+ * Returns the VLAN tag associated with an FC via network configuration.
+ *
+ * The VLAN tag to be selected should be configured in at least one of the
+ * FC LTPs and no different tag should be present in the rest of the FC LTPs.
+ *
+ * @param fc the FC to check
+ * @return an Optional object with the VLAN to be associated with the FC if
+ * one was found; an empty Optional object otherwise
+ */
+ private Optional<VlanId> getCfgVlan(CarrierEthernetForwardingConstruct fc) {
+ VlanId cfgVlan = null;
+ for (CarrierEthernetLogicalTerminationPoint ltp : fc.ltpSet()) {
+ VlanId tmpVlan = portVlanMap.get(ltp.cp());
+ if (tmpVlan == null) {
+ continue;
+ } else if (cfgVlan != null && cfgVlan != tmpVlan) {
+ log.warn("Multiple configured S-TAGs for the same FC");
+ return Optional.empty();
+ } else {
+ cfgVlan = tmpVlan;
+ }
+ }
+ return cfgVlan == null ? Optional.empty() : Optional.of(cfgVlan);
+ }
+
+ private class InternalNetworkConfigListener implements NetworkConfigListener {
+
+ /**
+ * Negative events.
+ */
+ private final EnumSet<NetworkConfigEvent.Type> negative
+ = EnumSet.of(NetworkConfigEvent.Type.CONFIG_UNREGISTERED,
+ NetworkConfigEvent.Type.CONFIG_REMOVED);
+
+ /**
+ * Actual configuration events.
+ */
+ private final EnumSet<NetworkConfigEvent.Type> actualConfig
+ = EnumSet.of(NetworkConfigEvent.Type.CONFIG_ADDED,
+ NetworkConfigEvent.Type.CONFIG_REMOVED,
+ NetworkConfigEvent.Type.CONFIG_UPDATED);
+
+ @Override
+ public boolean isRelevant(NetworkConfigEvent event) {
+ return event.configClass().equals(PortVlanConfig.class) &&
+ actualConfig.contains(event.type());
+ }
+
+ @Override
+ public void event(NetworkConfigEvent event) {
+
+ if (!isRelevant(event)) {
+ return;
+ }
+
+ ConnectPoint cp = (ConnectPoint) event.subject();
+ PortVlanConfig config = networkConfigService.getConfig(cp, PortVlanConfig.class);
+
+ if (config == null) {
+ log.info("VLAN tag config is removed from port {}", cp);
+ portVlanMap.remove(cp);
+ return;
+ }
+
+ if (config.portVlanId().isPresent() && !negative.contains(event.type())) {
+ VlanId assignedVlan = config.portVlanId().get();
+ if (usedVlans().contains(assignedVlan)) {
+ log.warn("VLAN tag {} is already used in the CE network", assignedVlan);
+ } else {
+ log.info("VLAN tag {} is assigned to port {}", assignedVlan, cp);
+ portVlanMap.put(cp, assignedVlan);
+ }
+ } else {
+ log.info("VLAN tag is removed from port {}", cp);
+ portVlanMap.remove(cp);
+ }
+ }
+ }
+}
+
diff --git a/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/channel/ControlChannelManager.java b/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/channel/ControlChannelManager.java
new file mode 100644
index 0000000..4bce91f
--- /dev/null
+++ b/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/channel/ControlChannelManager.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2017-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.opencord.ce.global.orchestration.channel;
+
+import com.google.common.collect.ImmutableSet;
+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.opencord.ce.api.services.channel.ControlChannelListenerService;
+import org.opencord.ce.api.services.MetroNetworkVirtualNodeService;
+import org.slf4j.Logger;
+
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArraySet;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+
+/**
+ * Implementation o the {@link ControlChannelListenerService}.
+ */
+@Component(immediate = true)
+@Service
+public class ControlChannelManager implements ControlChannelListenerService {
+
+ private final Logger log = getLogger(getClass());
+ private Set<MetroNetworkVirtualNodeService> sbListeners = new CopyOnWriteArraySet<>();
+
+ @Activate
+ public void activate() {
+ log.info("Started");
+ }
+
+ @Deactivate
+ public void deactivate() {
+ log.info("Stopped");
+ }
+
+ @Override
+ public void addListener(MetroNetworkVirtualNodeService listener) {
+ log.debug("listener added");
+ sbListeners.add(listener);
+ }
+
+ @Override
+ public void removeListener(MetroNetworkVirtualNodeService listener) {
+ sbListeners.remove(listener);
+ }
+
+ @Override
+ public Set<MetroNetworkVirtualNodeService> listeners() {
+ return ImmutableSet.copyOf(sbListeners);
+ }
+
+}
diff --git a/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/channel/package-info.java b/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/channel/package-info.java
new file mode 100644
index 0000000..9b98ec4
--- /dev/null
+++ b/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/channel/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-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.
+ */
+
+/**
+ * Communication channel APIs.
+ */
+package org.opencord.ce.global.orchestration.channel;
\ No newline at end of file
diff --git a/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/cli/commands/CarrierEthernetCreateEvcCommand.java b/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/cli/commands/CarrierEthernetCreateEvcCommand.java
new file mode 100644
index 0000000..2fc97ec
--- /dev/null
+++ b/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/cli/commands/CarrierEthernetCreateEvcCommand.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2017-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.opencord.ce.global.orchestration.cli.commands;
+
+import com.google.common.collect.Lists;
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
+import org.onosproject.cli.AbstractShellCommand;
+import org.opencord.ce.api.models.CarrierEthernetVirtualConnection;
+import org.opencord.ce.api.models.EvcConnId;
+import org.opencord.ce.api.services.MetroOrchestrationService;
+
+import java.util.List;
+
+import static org.opencord.ce.api.models.CarrierEthernetEvcUtils.generateEvcType;
+import static org.opencord.ce.api.models.CarrierEthernetEvcUtils.generateUniSet;
+import static org.opencord.ce.api.models.CarrierEthernetEvcUtils.generateMaxNumUni;
+
+/**
+ * CLI command for installing an Ethernet Virtual Connection.
+ */
+@Command(scope = "onos", name = "ce-evc-create",
+ description = "Carrier Ethernet EVC creation command.")
+public class CarrierEthernetCreateEvcCommand extends AbstractShellCommand {
+ @Argument(index = 0, name = "argEvcCfgId",
+ description = "EVC configuration ID", required = true, multiValued = false)
+ String argEvcCfgId = null;
+ @Argument(index = 1, name = "argEvcType", description =
+ "EVC type (defaults to POINT_TO_POINT or MULTIPOINT_TO_MULTIPOINT, depending on number of UNIs)",
+ required = false, multiValued = false)
+ String argEvcType = null;
+
+ @Argument(index = 2, name = "argUniList",
+ description = "List of UNIs (if point to multipoint, first is root, other are leaves)",
+ required = true, multiValued = true)
+ List<String> argUniList = Lists.newArrayList();
+ @Option(name = "-v", aliases = "--cevlan", description = "CE-VLAN ID (applied to all UNIs)",
+ required = false, multiValued = false)
+ short argCeVlanId = -1;
+ @Option(name = "-id", aliases = "--evc-id", description = "The ID of a evc to be updated" +
+ " (if evc does not exist, a new evc will be installed)", required = false, multiValued = false)
+ String argEvcId = null;
+ @Option(name = "-u", aliases = "--maxNumUni", description = "The maximum number of UNIs in the EVC",
+ required = false, multiValued = false)
+ int argMaxNumUni = -1;
+ @Option(name = "-c", aliases = "--cir", description = "The CIR in Mbps", required = false, multiValued = false)
+ double argCir = 0;
+ @Option(name = "-e", aliases = "--eir", description = "The EIR in Mbps", required = false, multiValued = false)
+ double argEir = 0;
+ @Option(name = "-cbs", aliases = "--cbs", description = "The CBS in Bytes", required = false, multiValued = false)
+ long argCbs = 0;
+ @Option(name = "-ebs", aliases = "--ebs", description = "The EBS in Bytes", required = false, multiValued = false)
+ long argEbs = 0;
+
+ // TODO: Add further arguments for VLAN tag preservation, CoS preservation etc.
+
+ @Override
+ protected void execute() {
+ MetroOrchestrationService ceManager = get(MetroOrchestrationService.class);
+ ceManager.installEvc(CarrierEthernetVirtualConnection.builder()
+ .id(EvcConnId.of(argEvcId == null ? argEvcCfgId : argEvcId))
+ .cfgId(argEvcCfgId)
+ .type(generateEvcType(argEvcType, argUniList))
+ .maxNumUni(generateMaxNumUni(argMaxNumUni, argEvcType, argUniList))
+ .uniSet(generateUniSet(argEvcType, argUniList.subList(1, argUniList.size()),
+ argCeVlanId, argUniList.get(0), argEvcCfgId, argCir,
+ argEir, argCbs, argEbs))
+ .build());
+ }
+}
diff --git a/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/cli/commands/CarrierEthernetListEvcsCommand.java b/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/cli/commands/CarrierEthernetListEvcsCommand.java
new file mode 100644
index 0000000..57fe6d5
--- /dev/null
+++ b/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/cli/commands/CarrierEthernetListEvcsCommand.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2017-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.opencord.ce.global.orchestration.cli.commands;
+
+import org.apache.karaf.shell.commands.Command;
+import org.onosproject.cli.AbstractShellCommand;
+import org.opencord.ce.api.models.CarrierEthernetVirtualConnection;
+import org.opencord.ce.api.services.MetroOrchestrationService;
+
+import java.util.Collection;
+
+
+/**
+ * CLI command for listing all installed CE services.
+ */
+@Command(scope = "onos", name = "ce-evc-list",
+ description = "Lists all installed EVCs.")
+public class CarrierEthernetListEvcsCommand extends AbstractShellCommand {
+
+ @Override
+ protected void execute() {
+ MetroOrchestrationService ceManager = get(MetroOrchestrationService.class);
+ printServices(ceManager.evcMap().values());
+ }
+
+ private void printServices(Collection<CarrierEthernetVirtualConnection> services) {
+ services.forEach(service -> print(" %s", service));
+ }
+}
diff --git a/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/cli/commands/CarrierEthernetListUnisCommand.java b/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/cli/commands/CarrierEthernetListUnisCommand.java
new file mode 100644
index 0000000..bf92286
--- /dev/null
+++ b/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/cli/commands/CarrierEthernetListUnisCommand.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2017-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.opencord.ce.global.orchestration.cli.commands;
+
+import org.apache.karaf.shell.commands.Command;
+import org.onosproject.cli.AbstractShellCommand;
+import org.opencord.ce.api.models.CarrierEthernetUni;
+import org.opencord.ce.api.services.MetroOrchestrationService;
+
+import java.util.Collection;
+
+/**
+ * CLI command for listing all CE UNIs.
+ */
+@Command(scope = "onos", name = "ce-uni-list",
+ description = "Lists all Carrier Ethernet UNIs.")
+public class CarrierEthernetListUnisCommand extends AbstractShellCommand {
+
+ @Override
+ protected void execute() {
+ MetroOrchestrationService ceManager = get(MetroOrchestrationService.class);
+ // Populate global UNI map
+ ceManager.getUnisFromTopo(false, false).forEach(uni -> ceManager.addGlobalUni(uni));
+ printUnis(ceManager.getUniMap().values());
+ }
+
+ private void printUnis(Collection<CarrierEthernetUni> unis) {
+ unis.forEach(uni -> print(" %s", uni));
+ }
+}
diff --git a/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/cli/commands/package-info.java b/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/cli/commands/package-info.java
new file mode 100644
index 0000000..471a619
--- /dev/null
+++ b/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/cli/commands/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-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.
+ */
+
+/**
+ * Command classes for the Carrier Ethernet app CLI.
+ */
+package org.opencord.ce.global.orchestration.cli.commands;
\ No newline at end of file
diff --git a/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/cli/completers/CarrierEthernetEvcTypeCompleter.java b/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/cli/completers/CarrierEthernetEvcTypeCompleter.java
new file mode 100644
index 0000000..f5ad4bc
--- /dev/null
+++ b/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/cli/completers/CarrierEthernetEvcTypeCompleter.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2017-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.opencord.ce.global.orchestration.cli.completers;
+
+import org.apache.karaf.shell.console.Completer;
+import org.apache.karaf.shell.console.completer.StringsCompleter;
+import org.opencord.ce.api.models.CarrierEthernetVirtualConnection;
+
+import java.util.List;
+import java.util.SortedSet;
+
+public class CarrierEthernetEvcTypeCompleter implements Completer {
+ @Override
+ public int complete(String buffer, int cursor, List<String> candidates) {
+
+ StringsCompleter delegate = new StringsCompleter();
+
+ SortedSet<String> strings = delegate.getStrings();
+
+ for (CarrierEthernetVirtualConnection.Type type : CarrierEthernetVirtualConnection.Type.values()) {
+ strings.add(type.name());
+ }
+
+ return delegate.complete(buffer, cursor, candidates);
+ }
+
+}
diff --git a/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/cli/completers/CarrierEthernetUniCompleter.java b/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/cli/completers/CarrierEthernetUniCompleter.java
new file mode 100644
index 0000000..951acba
--- /dev/null
+++ b/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/cli/completers/CarrierEthernetUniCompleter.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2017-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.opencord.ce.global.orchestration.cli.completers;
+
+import org.apache.karaf.shell.console.completer.StringsCompleter;
+import org.onosproject.cli.AbstractCompleter;
+import org.onosproject.cli.AbstractShellCommand;
+import org.opencord.ce.api.services.MetroOrchestrationService;
+
+import java.util.List;
+import java.util.SortedSet;
+
+/**
+ * UNI id completer, including only UNIs that have been added to the UNI map.
+ */
+public class CarrierEthernetUniCompleter extends AbstractCompleter {
+
+ @Override
+ public int complete(String buffer, int cursor, List<String> candidates) {
+
+ StringsCompleter delegate = new UniqueStringsCompleter();
+ SortedSet<String> strings = delegate.getStrings();
+
+ MetroOrchestrationService ceManager = AbstractShellCommand.get(MetroOrchestrationService.class);
+ ceManager.getUniMap().keySet().forEach(uniId -> strings.add(uniId));
+
+ return delegate.complete(buffer, cursor, candidates);
+ }
+
+}
\ No newline at end of file
diff --git a/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/cli/completers/CarrierEthernetValidUniCompleter.java b/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/cli/completers/CarrierEthernetValidUniCompleter.java
new file mode 100644
index 0000000..51182d4
--- /dev/null
+++ b/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/cli/completers/CarrierEthernetValidUniCompleter.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2017-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.opencord.ce.global.orchestration.cli.completers;
+
+import org.apache.karaf.shell.console.completer.StringsCompleter;
+import org.onosproject.cli.AbstractCompleter;
+import org.onosproject.cli.AbstractShellCommand;
+import org.opencord.ce.api.services.MetroOrchestrationService;
+
+import java.util.List;
+import java.util.SortedSet;
+
+/**
+ * UNI id completer, not including UNIs that have been removed.
+ */
+public class CarrierEthernetValidUniCompleter extends AbstractCompleter {
+
+ @Override
+ public int complete(String buffer, int cursor, List<String> candidates) {
+
+ StringsCompleter delegate = new UniqueStringsCompleter();
+ SortedSet<String> strings = delegate.getStrings();
+
+ MetroOrchestrationService ceManager = AbstractShellCommand.get(MetroOrchestrationService.class);
+ ceManager.getUnisFromTopo(false, false).forEach(uni -> strings.add(uni.id()));
+
+ return delegate.complete(buffer, cursor, candidates);
+ }
+}
diff --git a/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/cli/completers/UniqueStringsCompleter.java b/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/cli/completers/UniqueStringsCompleter.java
new file mode 100644
index 0000000..21272be
--- /dev/null
+++ b/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/cli/completers/UniqueStringsCompleter.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2017-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.opencord.ce.global.orchestration.cli.completers;
+
+import org.apache.felix.service.command.CommandSession;
+import org.apache.karaf.shell.console.CommandSessionHolder;
+import org.apache.karaf.shell.console.completer.ArgumentCompleter;
+import org.apache.karaf.shell.console.completer.StringsCompleter;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * String completer which excludes strings already included in the preceding argument list.
+ */
+public class UniqueStringsCompleter extends StringsCompleter {
+
+ @Override
+ public int complete(String buffer, int cursor, List candidates) {
+
+ // Get all preceding arguments
+ CommandSession session = CommandSessionHolder.getSession();
+ List<String> prevArgsList = Arrays.asList(((ArgumentCompleter.ArgumentList) session
+ .get("ARGUMENTS_LIST")).getArguments());
+
+ super.complete(buffer, cursor, candidates);
+
+ // Remove from candidate list all strings included in preceding arguments
+ candidates.removeAll(prevArgsList);
+
+ return candidates.isEmpty() ? -1 : 0;
+ }
+
+}
diff --git a/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/cli/completers/package-info.java b/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/cli/completers/package-info.java
new file mode 100644
index 0000000..9e95562
--- /dev/null
+++ b/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/cli/completers/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-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.
+ */
+
+/**
+ * Completer classes for the Carrier Ethernet app CLI.
+ */
+package org.opencord.ce.global.orchestration.cli.completers;
\ No newline at end of file
diff --git a/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/cli/package-info.java b/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/cli/package-info.java
new file mode 100644
index 0000000..0a4cf4f
--- /dev/null
+++ b/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/cli/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-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.
+ */
+
+/**
+ * CLI implementation for the Carrier Ethernet Application.
+ */
+package org.opencord.ce.global.orchestration.cli;
\ No newline at end of file
diff --git a/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/package-info.java b/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/package-info.java
new file mode 100644
index 0000000..e68df70
--- /dev/null
+++ b/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-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.
+ */
+
+/**
+ * Global metro orchestration package.
+ */
+package org.opencord.ce.global.orchestration;
\ No newline at end of file
diff --git a/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/rest/CarrierEthernetWebApplication.java b/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/rest/CarrierEthernetWebApplication.java
new file mode 100644
index 0000000..85a480e
--- /dev/null
+++ b/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/rest/CarrierEthernetWebApplication.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2017-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.opencord.ce.global.orchestration.rest;
+
+import org.onlab.rest.AbstractWebApplication;
+
+import java.util.Set;
+
+/**
+ * CarrierEthernet REST API web application.
+ */
+public class CarrierEthernetWebApplication extends AbstractWebApplication {
+ @Override
+ public Set<Class<?>> getClasses() {
+ return getClasses(CarrierEthernetWebResource.class);
+ }
+}
diff --git a/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/rest/CarrierEthernetWebResource.java b/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/rest/CarrierEthernetWebResource.java
new file mode 100644
index 0000000..39234b8
--- /dev/null
+++ b/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/rest/CarrierEthernetWebResource.java
@@ -0,0 +1,129 @@
+/*
+ * Copyright 2017-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.opencord.ce.global.orchestration.rest;
+
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onosproject.rest.AbstractWebResource;
+import org.opencord.ce.api.models.CarrierEthernetVirtualConnection;
+import org.opencord.ce.api.models.EvcConnId;
+import org.opencord.ce.api.services.MetroOrchestrationService;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Carrier Ethernet web resource.
+ */
+@Path("evc")
+public class CarrierEthernetWebResource extends AbstractWebResource {
+
+ private static final String EVCS = "evcs";
+ private final ObjectNode root = mapper().createObjectNode();
+ private final ArrayNode evcsNode = root.putArray(EVCS);
+
+ private MetroOrchestrationService ceManager = get(MetroOrchestrationService.class);
+
+ /**
+ * Gets all EVC entries. Returns array of all EVCs in the system.
+ *
+ * @return 200 OK with a collection of Evcs
+ */
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getEvcs() {
+ ceManager.evcMap().values().forEach(evc -> evcsNode.add(
+ codec(CarrierEthernetVirtualConnection.class)
+ .encode(evc, this)));
+
+
+ return ok(root).build();
+ }
+
+ /**
+ * Gets an EVC entry by deviceId.
+ * @param evcId evc ID
+ * @return 200 OK with the requested Evc.
+ */
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("{evcId}")
+ public Response getEvc(@PathParam("evcId") String evcId) {
+ ObjectNode evc = codec(CarrierEthernetVirtualConnection.class)
+ .encode(ceManager.getEvc(EvcConnId.of(evcId)), this);
+ return ok(evc).build();
+ }
+
+ /**
+ * Install an EVC with given parameters.
+ *
+ * @param stream input stream
+ * @return 200 OK if the EVC was installed
+ */
+ @POST
+ @Produces(MediaType.APPLICATION_JSON)
+ @Consumes(MediaType.APPLICATION_JSON)
+ public Response setEvc(InputStream stream) {
+ ObjectNode root = mapper().createObjectNode();
+ try {
+ ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ CarrierEthernetVirtualConnection evc =
+ codec(CarrierEthernetVirtualConnection.class).decode(jsonTree, this);
+ ceManager.installEvc(evc);
+ root.put("evcId", evc.id().id());
+ } catch (IOException e) {
+ throw new IllegalArgumentException(e.getMessage());
+ }
+ return ok(root).build();
+ }
+
+ /**
+ * Removes all EVCs installed in the CE app.
+ *
+ * @return 204 NO CONTENT
+ */
+ @DELETE
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response removeAllEvc() {
+ ceManager.removeAllEvcs();
+ return Response.noContent().build();
+ }
+
+ /**
+ * Removes one EVCs by evcId.
+ *
+ * @param evcId the EVC to remove.
+ * @return 204 NO CONTENT
+ */
+ @DELETE
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("{evcId}")
+ public Response removeEvcWithId(@PathParam("evcId") String evcId) {
+ ceManager.removeEvc(EvcConnId.of(evcId));
+ return Response.noContent().build();
+ }
+
+}
diff --git a/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/rest/package-info.java b/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/rest/package-info.java
new file mode 100644
index 0000000..d3a0873
--- /dev/null
+++ b/global/ce-orchestration/src/main/java/org/opencord/ce/global/orchestration/rest/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-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.
+ */
+
+/**
+ * REST API to setup Carrier Ethernet circuits.
+ */
+package org.opencord.ce.global.orchestration.rest;
\ No newline at end of file
diff --git a/global/ce-orchestration/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/global/ce-orchestration/src/main/resources/OSGI-INF/blueprint/shell-config.xml
new file mode 100644
index 0000000..ea08bbd
--- /dev/null
+++ b/global/ce-orchestration/src/main/resources/OSGI-INF/blueprint/shell-config.xml
@@ -0,0 +1,41 @@
+<!--
+ ~ Copyright 2017-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.
+ -->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+
+ <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
+ <command>
+ <action class="org.opencord.ce.global.orchestration.cli.commands.CarrierEthernetListUnisCommand"/>
+ </command>
+ <command>
+ <action class="org.opencord.ce.global.orchestration.cli.commands.CarrierEthernetCreateEvcCommand"/>
+ <completers>
+ <ref component-id="placeholderCompleter"/>
+ <ref component-id="carrierEthernetEvcTypeCompleter"/>
+ <ref component-id="carrierEthernetValidUniCompleter"/>
+ <ref component-id="carrierEthernetValidUniCompleter"/>
+ </completers>
+ </command>
+ <command>
+ <action class="org.opencord.ce.global.orchestration.cli.commands.CarrierEthernetListEvcsCommand"/>
+ </command>
+ </command-bundle>
+
+ <bean id="placeholderCompleter" class="org.onosproject.cli.PlaceholderCompleter"/>
+ <bean id="carrierEthernetEvcTypeCompleter" class="org.opencord.ce.global.orchestration.cli.completers.CarrierEthernetEvcTypeCompleter"/>
+ <bean id="carrierEthernetUniCompleter" class="org.opencord.ce.global.orchestration.cli.completers.CarrierEthernetUniCompleter"/>
+ <bean id="carrierEthernetValidUniCompleter" class="org.opencord.ce.global.orchestration.cli.completers.CarrierEthernetValidUniCompleter"/>
+
+</blueprint>
diff --git a/global/ce-orchestration/src/main/webapp/WEB-INF/web.xml b/global/ce-orchestration/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..99cfcf2
--- /dev/null
+++ b/global/ce-orchestration/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2017-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.
+ -->
+<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+ id="ONOS" version="2.5">
+ <display-name>ECORD REST API v1.0</display-name>
+
+ <servlet>
+ <servlet-name>JAX-RS Service</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.opencord.ce.global.orchestration.rest.CarrierEthernetWebApplication</param-value>
+ </init-param>
+ <load-on-startup>10</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>JAX-RS Service</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/global/config-samples/ecord-global-config.json b/global/config-samples/ecord-global-config.json
new file mode 100644
index 0000000..5b9e72a
--- /dev/null
+++ b/global/config-samples/ecord-global-config.json
@@ -0,0 +1,57 @@
+{
+ "apps" : {
+ "org.opencord.ce.global.vprovider" : {
+ "xos" : {
+ "username" : "xosadmin@opencord.org",
+ "password" : "0Ui8QNJNCdXrjjLpF1U6",
+ "address" : "127.0.0.1",
+ "resource" : "/xosapi/v1/metronet/usernetworkinterfaces/"
+ }
+ },
+ "org.opencord.ce.global.channel.http" : {
+ "endPoints" : {
+ "port" : "8182",
+ "topics" : [
+ "ecord-domains-topic-one",
+ "ecord-domains-topic-two",
+ "ecord-domains-topic-three"
+ ],
+ "domains" :
+ [
+ {
+ "domainId" : "domain1-onos-fabric",
+ "publicIp" : "10.128.14.10",
+ "port" : "8181",
+ "username" : "sdn",
+ "password" : "rocks",
+ "topic" : "ecord-domains-topic-one"
+ },
+ {
+ "domainId" : "domain1-onos-cord",
+ "publicIp" : "10.128.14.10",
+ "port" : "8182",
+ "username" : "sdn",
+ "password" : "rocks",
+ "topic" : "ecord-domains-topic-one"
+ },
+ {
+ "domainId" : "domain2-onos-fabric",
+ "publicIp" : "10.128.14.20",
+ "port" : "8181",
+ "username" : "sdn",
+ "password" : "rocks",
+ "topic" : "ecord-domains-topic-one"
+ },
+ {
+ "domainId" : "domain2-onos-cord",
+ "publicIp" : "10.128.14.20",
+ "port" : "8182",
+ "username" : "sdn",
+ "password" : "rocks",
+ "topic" : "ecord-domains-topic-one"
+ }
+ ]
+ }
+ }
+ }
+}
diff --git a/global/http-channel/pom.xml b/global/http-channel/pom.xml
new file mode 100644
index 0000000..76f81e5
--- /dev/null
+++ b/global/http-channel/pom.xml
@@ -0,0 +1,106 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2017-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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.opencord.ce</groupId>
+ <artifactId>global</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>global-channel</artifactId>
+ <packaging>bundle</packaging>
+ <version>1.0.0-SNAPSHOT</version>
+
+ <description>HTTP communication channel between hierarchical ONOS controllers</description>
+
+ <properties>
+ <web.context>/ecord/global</web.context>
+ <onos.app.name>org.opencord.ce.global.channel</onos.app.name>
+ <onos.version>1.10.6</onos.version>
+ <onos.app.url>http://opencord.org</onos.app.url>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.opencord.ce</groupId>
+ <artifactId>orchestration</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-api</artifactId>
+ <version>${onos.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-core-serializers</artifactId>
+ <version>${onos.version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <_wab>src/main/webapp/</_wab>
+ <Bundle-SymbolicName>
+ ${project.groupId}.${project.artifactId}
+ </Bundle-SymbolicName>
+ <Import-Package>
+ *,org.glassfish.jersey.servlet
+ </Import-Package>
+ <Web-ContextPath>${web.context}</Web-ContextPath>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+ <repositories>
+ <repository>
+ <id>snapshots</id>
+ <url>https://oss.sonatype.org/content/repositories/snapshots</url>
+ <releases><enabled>false</enabled></releases>
+ </repository>
+ </repositories>
+
+ <pluginRepositories>
+ <pluginRepository>
+ <id>snapshots</id>
+ <url>https://oss.sonatype.org/content/repositories/snapshots</url>
+ <releases><enabled>false</enabled></releases>
+ </pluginRepository>
+ </pluginRepositories>
+
+</project>
diff --git a/global/http-channel/src/main/java/org/opencord/ce/global/channel/client/ConnectionConfig.java b/global/http-channel/src/main/java/org/opencord/ce/global/channel/client/ConnectionConfig.java
new file mode 100644
index 0000000..ca7388a
--- /dev/null
+++ b/global/http-channel/src/main/java/org/opencord/ce/global/channel/client/ConnectionConfig.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2017-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.opencord.ce.global.channel.client;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.google.common.collect.Sets;
+import org.onlab.packet.IpAddress;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.net.config.Config;
+import org.onosproject.net.domain.DomainId;
+import org.opencord.ce.api.models.DomainEndPoint;
+
+import java.util.ArrayList;
+import java.util.Set;
+
+/**
+ * Configuration class for this bundle.
+ *
+ * Look at /config-samples/ecord-global-config.json for a sample configuration
+ */
+public class ConnectionConfig extends Config<ApplicationId> {
+
+ private static final String PORT = "port";
+
+ private static final String TOPICS = "topics";
+
+ private static final String DOMAINS = "domains";
+ private static final String DOMAIN_ID = "domainId";
+ private static final String PUBLIC_IP = "publicIp";
+ private static final String USERNAME = "username";
+ private static final String PASSWD = "password";
+ private static final String TOPIC = "topic";
+
+ /**
+ * Gets listen port from configuration.
+ * @return port number
+ */
+ public int listenPort() {
+ return object.path(PORT).asInt();
+ }
+
+ /**
+ * List of topics to distribute network operations among ONOS instances.
+ * @return list of topics
+ */
+ public ArrayList<String> topics() {
+ ArrayList<String> topics = new ArrayList<>();
+ object.path(TOPICS).forEach(
+ topic -> topics.add(topic.asText())
+ );
+ return topics;
+ }
+
+ /**
+ * Returns set of domain end points.
+ * @return set of domain end points
+ */
+ public Set<DomainEndPoint> endPoints() {
+ JsonNode peersNode = object.get(DOMAINS);
+ Set<DomainEndPoint> endPoints = Sets.newHashSet();
+
+ peersNode.forEach(jsonNode -> {
+ DomainId domainId = DomainId.domainId(
+ jsonNode.path(DOMAIN_ID).asText());
+ IpAddress publicIp = IpAddress.valueOf(jsonNode.path(PUBLIC_IP).asText());
+ int port = jsonNode.path(PORT).asInt();
+
+ String username = jsonNode.path(USERNAME).asText();
+ String password = jsonNode.path(PASSWD).asText();
+
+ String topic = jsonNode.path(TOPIC).asText();
+
+ endPoints.add(new DomainEndPoint(domainId, publicIp, port,
+ username, password, topic));
+ });
+
+ return endPoints;
+ }
+}
diff --git a/global/http-channel/src/main/java/org/opencord/ce/global/channel/client/HttpClientComponent.java b/global/http-channel/src/main/java/org/opencord/ce/global/channel/client/HttpClientComponent.java
new file mode 100644
index 0000000..3939ac4
--- /dev/null
+++ b/global/http-channel/src/main/java/org/opencord/ce/global/channel/client/HttpClientComponent.java
@@ -0,0 +1,165 @@
+/*
+ * Copyright 2017-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.opencord.ce.global.channel.client;
+
+
+import com.google.common.collect.Sets;
+
+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.onosproject.cluster.ClusterService;
+import org.onosproject.cluster.LeadershipService;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.onosproject.net.config.ConfigFactory;
+import org.onosproject.net.config.NetworkConfigEvent;
+import org.onosproject.net.config.NetworkConfigListener;
+import org.onosproject.net.config.NetworkConfigRegistry;
+import org.onosproject.net.config.NetworkConfigService;
+import org.onosproject.net.config.basics.SubjectFactories;
+import org.onosproject.net.domain.DomainService;
+import org.opencord.ce.api.services.channel.ControlChannelListenerService;
+import org.opencord.ce.api.models.DomainEndPoint;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+
+/**
+ * Southbound component that adds a listener to the
+ * {@link ControlChannelListenerService}.
+ *
+ * Accomplishes network tasks through HTTP requests,
+ * acting as a client that send {@link org.opencord.ce.api.models.CarrierEthernetForwardingConstruct}
+ * requests to the underlying domains
+ */
+@Component(immediate = true)
+public class HttpClientComponent {
+ private static final String APP_NAME = "org.opencord.ce.global.channel.http";
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+ private ApplicationId appId;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected LeadershipService leadershipService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected ClusterService clusterService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected NetworkConfigRegistry configRegistry;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected NetworkConfigService configService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected CoreService coreService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected ControlChannelListenerService channelListenerService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected DomainService domainService;
+
+ private static boolean isRunningForLeadership = false;
+
+ private final Set<DomainEndPoint> endPoints = Sets.newHashSet();
+ private final List<String> topics = new ArrayList<>();
+
+ private final ExecutorService eventExecutor =
+ Executors.newSingleThreadExecutor();
+
+ private final ConfigFactory<ApplicationId, ConnectionConfig> configFactory =
+ new ConfigFactory<ApplicationId, ConnectionConfig>(SubjectFactories.APP_SUBJECT_FACTORY,
+ ConnectionConfig.class, "endPoints") {
+ @Override
+ public ConnectionConfig createConfig() {
+ return new ConnectionConfig();
+ }
+ };
+
+ private final NetworkConfigListener configListener = new InternalConfigListener();
+
+ @Activate
+ protected void activate() {
+ log.info("Started");
+
+ appId = coreService.registerApplication(APP_NAME);
+ configRegistry.registerConfigFactory(configFactory);
+ configService.addListener(configListener);
+ channelListenerService.addListener(HttpClientInstance.INSTANCE);
+ }
+
+ @Deactivate
+ protected void deactivate() {
+ log.info("Stopped");
+ configService.removeListener(configListener);
+ configRegistry.unregisterConfigFactory(configFactory);
+ channelListenerService.removeListener(HttpClientInstance.INSTANCE);
+ if (isRunningForLeadership) {
+ topics.forEach(topic -> leadershipService.withdraw(topic));
+ }
+ }
+
+ private void runForLeadership(List<String> topics) {
+ topics.forEach(topic ->
+ leadershipService.runForLeadership(topic));
+ isRunningForLeadership = true;
+ }
+
+
+ private void readConfig() {
+ ConnectionConfig config = configRegistry.getConfig(appId, ConnectionConfig.class);
+ log.debug("Domains connections config received");
+
+ endPoints.addAll(config.endPoints());
+ topics.addAll(config.topics());
+ runForLeadership(topics);
+ HttpClientInstance.INSTANCE.configure(clusterService, leadershipService, domainService, endPoints);
+ }
+
+ private class InternalConfigListener implements NetworkConfigListener {
+
+ @Override
+ public void event(NetworkConfigEvent event) {
+ if (!event.configClass().equals(ConnectionConfig.class)) {
+ return;
+ }
+ switch (event.type()) {
+ case CONFIG_ADDED:
+ log.info("Network configuration added");
+ eventExecutor.execute(HttpClientComponent.this::readConfig);
+ break;
+ case CONFIG_UPDATED:
+ log.info("Network configuration updated");
+ eventExecutor.execute(HttpClientComponent.this::readConfig);
+ break;
+ default:
+ break;
+ }
+ }
+ }
+}
diff --git a/global/http-channel/src/main/java/org/opencord/ce/global/channel/client/HttpClientInstance.java b/global/http-channel/src/main/java/org/opencord/ce/global/channel/client/HttpClientInstance.java
new file mode 100644
index 0000000..a6687a1
--- /dev/null
+++ b/global/http-channel/src/main/java/org/opencord/ce/global/channel/client/HttpClientInstance.java
@@ -0,0 +1,349 @@
+/*
+ * Copyright 2017-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.opencord.ce.global.channel.client;
+
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.collect.Maps;
+import org.apache.commons.lang3.tuple.Pair;
+import org.onosproject.codec.JsonCodec;
+import org.onosproject.net.domain.DomainId;
+import org.onosproject.net.domain.DomainService;
+import org.onosproject.cluster.ClusterService;
+import org.onosproject.cluster.LeadershipService;
+import org.onosproject.rest.AbstractWebResource;
+import org.opencord.ce.api.models.CarrierEthernetForwardingConstruct;
+import org.opencord.ce.api.models.CarrierEthernetNetworkInterface;
+import org.opencord.ce.api.models.CarrierEthernetUni;
+import org.opencord.ce.api.models.DomainEndPoint;
+import org.opencord.ce.api.models.EvcConnId;
+import org.opencord.ce.api.services.MetroNetworkVirtualNodeService;
+import org.opencord.ce.api.services.channel.RequestCallback;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutorService;
+
+
+import static java.util.concurrent.Executors.newSingleThreadExecutor;
+import static org.opencord.ce.api.services.channel.Symbols.BASE_URL;
+import static org.opencord.ce.api.services.channel.Symbols.COLON;
+import static org.opencord.ce.api.services.channel.Symbols.DELETE;
+import static org.opencord.ce.api.services.channel.Symbols.DOUBLESLASH;
+import static org.opencord.ce.api.services.channel.Symbols.DST_NI_LIST;
+import static org.opencord.ce.api.services.channel.Symbols.FC;
+import static org.opencord.ce.api.services.channel.Symbols.GET;
+import static org.opencord.ce.api.services.channel.Symbols.HTTP;
+import static org.opencord.ce.api.services.channel.Symbols.POST;
+import static org.opencord.ce.api.services.channel.Symbols.SRC_NI;
+import static org.opencord.ce.api.services.channel.Symbols.UNI;
+import static org.onosproject.net.domain.DomainId.LOCAL;
+
+/**
+ * Implementation of the listener methods for requesting {@link
+ * org.opencord.ce.api.models.CarrierEthernetForwardingConstruct} configuration.
+ */
+public enum HttpClientInstance
+ implements MetroNetworkVirtualNodeService {
+ INSTANCE;
+ private final Logger log =
+ LoggerFactory.getLogger(HttpClientInstance.class);
+
+ private static final int STATUS_OK = Response.Status.OK.getStatusCode();
+ private static final int STATUS_REQ_UNPROCESSABLE = Response.Status.NOT_ACCEPTABLE.getStatusCode();
+
+ private final Map<DomainId, Pair<Client, DomainEndPoint>> domainsEndPointsMap = Maps.newConcurrentMap();
+
+ private final AbstractWebResource codecContext = new AbstractWebResource();
+
+ private boolean configured = false;
+
+ private ClusterService clusterService;
+ private LeadershipService leadershipService;
+ private DomainService domainService;
+
+ private final ExecutorService networkExecutor =
+ newSingleThreadExecutor();
+ // newFixedThreadPool(5, groupedThreads("opencord/ecord-http", "event-handler"));
+
+ public void configure(ClusterService clusterService, LeadershipService leadershipService,
+ DomainService domainService, Set<DomainEndPoint> endPoints) {
+
+ if (!configured) {
+ this.clusterService = clusterService;
+ this.leadershipService = leadershipService;
+ this.domainService = domainService;
+ configured = true;
+ }
+ endPoints.forEach(siteConfig -> {
+ DomainId domainId = siteConfig.domainId();
+ synchronized (this) {
+ domainsEndPointsMap.putIfAbsent(domainId,
+ Pair.of(createClient(), siteConfig));
+ notify();
+ }
+ });
+ }
+
+ public Client getConnectionInfo(DomainId domainId) {
+ return domainsEndPointsMap.get(domainId).getLeft();
+ }
+
+ private boolean isLeader(String topic) {
+ return topic != null && leadershipService.getLeader(topic).id()
+ .equals(clusterService.getLocalNode().id().id());
+ }
+
+ private boolean checkReply(Response response) {
+ if (response != null) {
+ return checkStatusCode(response.getStatus());
+ }
+ log.error("Null reply from end point");
+ return false;
+ }
+
+ private boolean checkStatusCode(int statusCode) {
+ if (statusCode == STATUS_OK) {
+ return true;
+ } else {
+ log.error("Failed request, HTTP error code : "
+ + statusCode);
+ return false;
+ }
+ }
+
+ private String getTopic(DomainId domainId) {
+ if (domainsEndPointsMap.get(domainId) != null) {
+ return domainsEndPointsMap.get(domainId).getRight().topic();
+ }
+ log.info("Domain ID {} not among configured domain IDs", domainId.id());
+ return null;
+ }
+
+ private Client createClient() {
+ return ClientBuilder.newClient();
+ }
+
+ @Override
+ public void setNodeForwarding(CarrierEthernetForwardingConstruct fc, CarrierEthernetNetworkInterface srcNi,
+ Set<CarrierEthernetNetworkInterface> dstNiSet) {
+
+ DomainId domainId = domainService.getDomain(srcNi.cp().deviceId());
+ if (domainId == LOCAL || !isLeader(getTopic(domainId))) {
+ return;
+ }
+ JsonCodec<CarrierEthernetForwardingConstruct> fcCodec =
+ codecContext.codec(CarrierEthernetForwardingConstruct.class);
+ JsonCodec<CarrierEthernetNetworkInterface> niCodec =
+ codecContext.codec(CarrierEthernetNetworkInterface.class);
+ ObjectNode body = codecContext.mapper().createObjectNode();
+
+ body.set(FC, fcCodec.encode(fc, codecContext));
+ body.set(SRC_NI, niCodec.encode(srcNi, codecContext));
+ ArrayNode dstNiJsonArrayNode = codecContext.mapper().createArrayNode();
+ dstNiSet.forEach(dstNi ->
+ dstNiJsonArrayNode.add(niCodec.encode(dstNi, codecContext)));
+ body.set(DST_NI_LIST, dstNiJsonArrayNode);
+ String resource = "/ForwardingConstruct";
+ networkExecutor.execute(new NetworkTask(domainId, POST, resource, body.toString(),
+ new RequestCallback() {
+ @Override
+ public void onSuccess(Response response) {
+ log.info("FC request submit to domain: {}", domainId);
+
+ }
+
+ @Override
+ public void onError(Response response) {
+ log.error("FC call failure reason: {}", response.getStatusInfo());
+
+ }
+ }));
+ }
+
+ @Override
+ public void createBandwidthProfileResources(CarrierEthernetForwardingConstruct fc, CarrierEthernetUni uni) {
+ DomainId domainId = domainService.getDomain(uni.cp().deviceId());
+ if (domainId == LOCAL || !isLeader(getTopic(domainId))) {
+ return;
+ }
+ String resource = "/createBwp";
+ networkExecutor.execute(new NetworkTask(domainId, POST, resource,
+ fcUniToRestBody(fc, uni).toString(),
+ new RequestCallback() {
+ @Override
+ public void onSuccess(Response response) {
+ log.info("BW profile creation request submitted to domain: {}", domainId);
+ }
+
+ @Override
+ public void onError(Response response) {
+ log.error("BwProfile creation call fail: {}", response.getStatusInfo());
+
+ }
+ }));
+ }
+
+ @Override
+ public void applyBandwidthProfileResources(CarrierEthernetForwardingConstruct fc, CarrierEthernetUni uni) {
+ DomainId domainId = domainService.getDomain(uni.cp().deviceId());
+ if (domainId == LOCAL || !isLeader(getTopic(domainId))) {
+ return;
+ }
+ String resource = "/applyBwp";
+ networkExecutor.execute(new NetworkTask(domainId, POST, resource, fcUniToRestBody(fc, uni).toString(),
+ new RequestCallback() {
+ @Override
+ public void onSuccess(Response response) {
+ log.info("BW profile activation request submitted to domain: {}", domainId);
+ }
+
+ @Override
+ public void onError(Response response) {
+ log.error("FAIL BW profile activation: {}", response.getStatusInfo());
+
+ }
+ }));
+ }
+
+ @Override
+ public void removeBandwidthProfileResources(CarrierEthernetForwardingConstruct fc, CarrierEthernetUni uni) {
+ DomainId domainId = domainService.getDomain(uni.cp().deviceId());
+ if (domainId == LOCAL || !isLeader(getTopic(domainId))) {
+ return;
+ }
+ String resource = "/deleteBwp";
+ networkExecutor.execute(new NetworkTask(domainId, POST, resource,
+ fcUniToRestBody(fc, uni).toString(),
+ new RequestCallback() {
+ @Override
+ public void onSuccess(Response response) {
+ log.info("BW profile creation request submitted to domain: {}", domainId);
+ }
+
+ @Override
+ public void onError(Response response) {
+ log.info("FAIL BW profile creation: {}", response.getStatusInfo());
+
+ }
+ }));
+ }
+
+ @Override
+ public void removeAllForwardingResources(EvcConnId fcId) {
+ Set<DomainId> domainIds = domainService.getDomainIds();
+ String resource = "/deleteFcResources/" + fcId.id();
+ domainIds.forEach(domainId -> {
+ if (isLeader(getTopic(domainId))) {
+ networkExecutor.execute(new NetworkTask(domainId, DELETE, resource,
+ null, new RequestCallback() {
+ @Override
+ public void onSuccess(Response response) {
+
+ }
+
+ @Override
+ public void onError(Response response) {
+
+ }
+ }));
+ }
+ });
+
+ }
+
+ private ObjectNode fcUniToRestBody(CarrierEthernetForwardingConstruct fc, CarrierEthernetUni uni) {
+ JsonCodec<CarrierEthernetForwardingConstruct> fcCodec =
+ codecContext.codec(CarrierEthernetForwardingConstruct.class);
+ JsonCodec<CarrierEthernetNetworkInterface> niCodec =
+ codecContext.codec(CarrierEthernetNetworkInterface.class);
+ ObjectNode body = codecContext.mapper().createObjectNode();
+ body.set(FC, fcCodec.encode(fc, codecContext));
+ body.set(UNI, niCodec.encode(uni, codecContext));
+ return body;
+ }
+
+ private class NetworkTask implements Runnable {
+ private String method;
+ private String resource;
+ private String body;
+ private DomainId domainId;
+ private RequestCallback callback;
+
+ NetworkTask(DomainId domainId, String method, String resource, String body,
+ RequestCallback callback) {
+ this.domainId = domainId;
+ this.method = method;
+ this.resource = resource;
+ this.body = body;
+ this.callback = callback;
+ }
+ @Override
+ public void run() {
+
+ synchronized (this) {
+ while (domainsEndPointsMap.get(domainId) == null) {
+ log.info("End point object missing for domain {}." +
+ "\nPossibly the Bundle configuration is missing ", domainId);
+ try {
+ wait();
+ } catch (InterruptedException ie) {
+ log.info("Interrupted exception: " + ie.getMessage());
+ }
+
+ }
+ }
+ DomainEndPoint endPoint = domainsEndPointsMap.get(domainId).getRight();
+
+ Client client = domainsEndPointsMap.get(domainId).getLeft();
+
+ String url = HTTP + COLON + DOUBLESLASH + endPoint.publicIp().toString() + COLON +
+ endPoint.port() + BASE_URL + "/carrierethernet" + resource;
+ log.info("DEBUG {}: Sending data via http: {}", url, body);
+
+ WebTarget webTarget = client.target(url);
+ Response response;
+ switch (method) {
+ case POST:
+ response = webTarget.request(MediaType.APPLICATION_JSON)
+ .post(Entity.entity(body, MediaType.APPLICATION_JSON));
+ break;
+ case DELETE:
+ response = webTarget.request(MediaType.APPLICATION_JSON).delete();
+ break;
+ case GET:
+ default:
+ response = webTarget.request(MediaType.APPLICATION_JSON).get();
+ break;
+ }
+
+ if (!checkReply(response)) {
+ callback.onError(response);
+ } else {
+ callback.onSuccess(response);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/global/http-channel/src/main/java/org/opencord/ce/global/channel/client/package-info.java b/global/http-channel/src/main/java/org/opencord/ce/global/channel/client/package-info.java
new file mode 100644
index 0000000..fd18189
--- /dev/null
+++ b/global/http-channel/src/main/java/org/opencord/ce/global/channel/client/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-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.
+ */
+
+/**
+ * Implementation of the client-side communication channel APIs.
+ */
+package org.opencord.ce.global.channel.client;
\ No newline at end of file
diff --git a/global/http-channel/src/main/java/org/opencord/ce/global/channel/package-info.java b/global/http-channel/src/main/java/org/opencord/ce/global/channel/package-info.java
new file mode 100644
index 0000000..a77b5a4
--- /dev/null
+++ b/global/http-channel/src/main/java/org/opencord/ce/global/channel/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-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.
+ */
+
+/**
+ * Implementation of the communication channel APIs.
+ */
+package org.opencord.ce.global.channel;
\ No newline at end of file
diff --git a/global/http-channel/src/main/java/org/opencord/ce/global/channel/server/DeviceResource.java b/global/http-channel/src/main/java/org/opencord/ce/global/channel/server/DeviceResource.java
new file mode 100644
index 0000000..96e6714
--- /dev/null
+++ b/global/http-channel/src/main/java/org/opencord/ce/global/channel/server/DeviceResource.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2017-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.opencord.ce.global.channel.server;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.opencord.ce.api.services.virtualprovider.DefaultDomainVirtualDevice;
+import org.opencord.ce.api.services.virtualprovider.DomainVirtualDevice;
+import org.opencord.ce.api.services.virtualprovider.EcordDeviceProviderService;
+import org.onosproject.codec.JsonCodec;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.Port;
+import org.onosproject.net.device.DefaultPortDescription;
+import org.onosproject.net.device.PortDescription;
+import org.onosproject.net.domain.DomainId;
+import org.onosproject.rest.AbstractWebResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Remote device REST control.
+ */
+@Path("/topology/{domainId}")
+public class DeviceResource extends AbstractWebResource {
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ private EcordDeviceProviderService ecordDeviceProviderService =
+ get(EcordDeviceProviderService.class);
+
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("{deviceId}")
+ public Response postDevice(@PathParam("domainId") String domainId, @PathParam("deviceId") String deviceId,
+ InputStream stream) {
+ log.info("Notified device from domainId {}", domainId);
+ try {
+ JsonNode responseBody = mapper().readTree(stream);
+ // the json body superfluous now. Can be used to add annotations to the device later
+ log.debug(responseBody.toString());
+ DomainVirtualDevice domainDevice = new DefaultDomainVirtualDevice(DeviceId.deviceId(deviceId),
+ DomainId.domainId(domainId));
+ ecordDeviceProviderService.connectRemoteDevice(domainDevice);
+ return Response.status(200).build();
+ } catch (IOException io) {
+ log.info("Json parse error");
+ return Response.status(Response.Status.NOT_ACCEPTABLE).build();
+ }
+ }
+
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("{deviceId}/ports")
+ public Response postBigSwitchPorts(@PathParam("domainId") String domainId, @PathParam("deviceId") String deviceId,
+ InputStream stream) {
+ log.info("Notified device port from domainId {}", domainId);
+ try {
+ JsonNode responseBody = mapper().readTree(stream);
+ log.debug(responseBody.toString());
+ JsonCodec<Port> portCodec = codec(Port.class);
+ List<PortDescription> ports = new ArrayList<>();
+ responseBody.forEach(item -> {
+ Port port = portCodec.decode((ObjectNode) item, this);
+ DefaultAnnotations.Builder annot = DefaultAnnotations.builder();
+ port.annotations().keys()
+ .forEach(k -> annot.set(k, port.annotations().value(k)));
+ ports.add(new DefaultPortDescription(port.number(), port.isEnabled(), port.type(),
+ port.portSpeed(), annot.build()));
+ });
+
+ ecordDeviceProviderService.addOrUpdateRemotePorts(DomainId.domainId(domainId),
+ DeviceId.deviceId(deviceId), ports);
+ return Response.status(200).build();
+
+ } catch (IOException io) {
+ log.info("Json parse error");
+ return Response.status(Response.Status.NOT_ACCEPTABLE).build();
+ }
+
+ }
+}
diff --git a/global/http-channel/src/main/java/org/opencord/ce/global/channel/server/EcordGlobalRestApp.java b/global/http-channel/src/main/java/org/opencord/ce/global/channel/server/EcordGlobalRestApp.java
new file mode 100644
index 0000000..c0d9afd
--- /dev/null
+++ b/global/http-channel/src/main/java/org/opencord/ce/global/channel/server/EcordGlobalRestApp.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2017-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.opencord.ce.global.channel.server;
+
+import org.onlab.rest.AbstractWebApplication;
+
+import java.util.Set;
+
+/**
+ * Loader class for web resource APIs.
+ */
+public class EcordGlobalRestApp extends AbstractWebApplication {
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ return getClasses(DeviceResource.class);
+ }
+}
diff --git a/global/http-channel/src/main/java/org/opencord/ce/global/channel/server/package-info.java b/global/http-channel/src/main/java/org/opencord/ce/global/channel/server/package-info.java
new file mode 100644
index 0000000..e82f4d2
--- /dev/null
+++ b/global/http-channel/src/main/java/org/opencord/ce/global/channel/server/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-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.
+ */
+
+/**
+ * Implementation of the server-side communication channel APIs.
+ */
+package org.opencord.ce.global.channel.server;
\ No newline at end of file
diff --git a/global/http-channel/src/main/webapp/WEB-INF/web.xml b/global/http-channel/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..07cceef
--- /dev/null
+++ b/global/http-channel/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2017-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.
+ -->
+<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+ id="ONOS" version="2.5">
+ <display-name>ECORD REST API v1.0</display-name>
+
+ <servlet>
+ <servlet-name>JAX-RS Service</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.opencord.ce.global.channel.server.EcordGlobalRestApp</param-value>
+ </init-param>
+ <load-on-startup>10</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>JAX-RS Service</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/global/pom.xml b/global/pom.xml
new file mode 100644
index 0000000..26f40d0
--- /dev/null
+++ b/global/pom.xml
@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2017-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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.opencord</groupId>
+ <artifactId>ce</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.opencord.ce</groupId>
+ <artifactId>global</artifactId>
+ <packaging>pom</packaging>
+ <version>1.0.0-SNAPSHOT</version>
+
+ <description>Multi-CORD orchestration of Carrier Ethernet services</description>
+
+ <properties>
+ <onos.version>1.10.6</onos.version>
+ <onos.app.title>E-CORD global orchestrator</onos.app.title>
+ <onos.app.url>http://opencord.org</onos.app.url>
+ </properties>
+
+ <modules>
+ <module>ce-orchestration</module>
+ <module>virtualprovider</module>
+ <module>http-channel</module>
+ <module>app</module>
+ </modules>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.opencord.ce</groupId>
+ <artifactId>ce-api</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+ <repositories>
+ <repository>
+ <id>snapshots</id>
+ <url>https://oss.sonatype.org/content/repositories/snapshots</url>
+ <releases><enabled>false</enabled></releases>
+ </repository>
+ </repositories>
+
+ <pluginRepositories>
+ <pluginRepository>
+ <id>snapshots</id>
+ <url>https://oss.sonatype.org/content/repositories/snapshots</url>
+ <releases><enabled>false</enabled></releases>
+ </pluginRepository>
+ </pluginRepositories>
+
+</project>
diff --git a/global/virtualprovider/pom.xml b/global/virtualprovider/pom.xml
new file mode 100644
index 0000000..0438e93
--- /dev/null
+++ b/global/virtualprovider/pom.xml
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2017-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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.opencord.ce</groupId>
+ <artifactId>global</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>virtualprovider</artifactId>
+ <packaging>bundle</packaging>
+
+ <description>Topology provider in the global orchestrator</description>
+
+ <properties>
+ <onos.app.name>org.opencord.ce.global.vprovider</onos.app.name>
+ <onos.version>1.10.6</onos.version>
+ <onos.app.url>http://opencord.org</onos.app.url>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-api</artifactId>
+ <version>${onos.version}</version>
+ </dependency>
+ </dependencies>
+
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+ <repositories>
+ <repository>
+ <id>snapshots</id>
+ <url>https://oss.sonatype.org/content/repositories/snapshots</url>
+ <releases><enabled>false</enabled></releases>
+ </repository>
+ </repositories>
+
+ <pluginRepositories>
+ <pluginRepository>
+ <id>snapshots</id>
+ <url>https://oss.sonatype.org/content/repositories/snapshots</url>
+ <releases><enabled>false</enabled></releases>
+ </pluginRepository>
+ </pluginRepositories>
+
+</project>
diff --git a/global/virtualprovider/src/main/java/org/opencord/ce/global/virtualdomain/VirtualDomainDeviceProvider.java b/global/virtualprovider/src/main/java/org/opencord/ce/global/virtualdomain/VirtualDomainDeviceProvider.java
new file mode 100644
index 0000000..d1bdefb
--- /dev/null
+++ b/global/virtualprovider/src/main/java/org/opencord/ce/global/virtualdomain/VirtualDomainDeviceProvider.java
@@ -0,0 +1,389 @@
+/*
+ * Copyright 2017-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.opencord.ce.global.virtualdomain;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+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.onosproject.net.config.basics.SubjectFactories;
+import org.opencord.ce.api.services.virtualprovider.DomainVirtualDevice;
+import org.opencord.ce.api.services.virtualprovider.EcordDeviceProviderService;
+import org.onlab.packet.ChassisId;
+import org.onosproject.cluster.ClusterService;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.onosproject.mastership.MastershipAdminService;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DefaultAnnotations;
+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.SparseAnnotations;
+import org.onosproject.net.config.ConfigFactory;
+import org.onosproject.net.config.NetworkConfigEvent;
+import org.onosproject.net.config.NetworkConfigListener;
+import org.onosproject.net.config.NetworkConfigRegistry;
+import org.onosproject.net.config.NetworkConfigService;
+import org.onosproject.net.device.DefaultDeviceDescription;
+import org.onosproject.net.device.DeviceDescription;
+import org.onosproject.net.device.DeviceProvider;
+import org.onosproject.net.device.DeviceProviderRegistry;
+import org.onosproject.net.device.DeviceProviderService;
+import org.onosproject.net.device.PortDescription;
+import org.onosproject.net.domain.DomainId;
+import org.onosproject.net.provider.ProviderId;
+import org.opencord.ce.api.models.CarrierEthernetEnni;
+import org.opencord.ce.api.models.CarrierEthernetGenericNi;
+import org.opencord.ce.api.models.CarrierEthernetInni;
+import org.opencord.ce.api.models.CarrierEthernetLogicalTerminationPoint;
+import org.opencord.ce.api.models.CarrierEthernetNetworkInterface;
+import org.opencord.ce.api.models.CarrierEthernetUni;
+import org.opencord.ce.api.services.MetroOrchestrationService;
+import org.opencord.ce.global.virtualdomain.config.EcordDriverConfig;
+import org.opencord.ce.global.virtualdomain.config.XosEndPointConfig;
+import org.slf4j.Logger;
+
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+
+import static java.util.concurrent.Executors.newFixedThreadPool;
+import static org.onlab.util.Tools.groupedThreads;
+import static org.onosproject.net.AnnotationKeys.DRIVER;
+import static org.onosproject.net.AnnotationKeys.LATITUDE;
+import static org.onosproject.net.AnnotationKeys.LONGITUDE;
+import static org.slf4j.LoggerFactory.getLogger;
+import static org.opencord.ce.api.models.CarrierEthernetNetworkInterface.Type;
+
+/**
+ * Exposes remote domain devices to the core.
+ */
+@Component(immediate = true)
+@Service(value = EcordDeviceProviderService.class)
+public class VirtualDomainDeviceProvider
+ implements DeviceProvider, EcordDeviceProviderService {
+ private final Logger log = getLogger(getClass());
+ public static final String PROVIDER_NAME = "org.opencord.ce.global.vprovider";
+ public static final ProviderId PROVIDER_ID = new ProviderId("domain", PROVIDER_NAME);
+ private static final String UNKNOWN = "unknown";
+ private static final String NO_LLDP = "no-lldp";
+ private static final String DOMAIN_ID = "domainId";
+ private static final String MEF_IF_TYPE = "mefIfType";
+
+ private ApplicationId appId;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected NetworkConfigRegistry configRegistry;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected NetworkConfigService configService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected CoreService coreService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected DeviceProviderRegistry deviceProviderRegistry;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected MastershipAdminService mastershipAdminService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected ClusterService clusterService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected MetroOrchestrationService metroOrchestrationService;
+
+ protected DeviceProviderService deviceProviderService;
+
+ private EcordDriverConfig ecordDriverConfig;
+ private XoSHttpClient xoSHttpClient;
+
+ private final NetworkConfigListener configListener = new InternalConfigListener();
+
+ /*
+ private final ConfigFactory<ApplicationId, EcordDriverConfig> diverConfigFactory =
+ new ConfigFactory<ApplicationId, EcordDriverConfig>(APP_SUBJECT_FACTORY,
+ EcordDriverConfig.class, "driver") {
+ @Override
+ public EcordDriverConfig createConfig() {
+ return new EcordDriverConfig();
+ }
+ };
+ */
+
+ private final ConfigFactory<ApplicationId, XosEndPointConfig> xosEndpointConfigFactory =
+ new ConfigFactory<ApplicationId, XosEndPointConfig>(SubjectFactories.APP_SUBJECT_FACTORY,
+ XosEndPointConfig.class, "xos") {
+ @Override
+ public XosEndPointConfig createConfig() {
+ return new XosEndPointConfig();
+ }
+ };
+
+ private final ExecutorService eventExecutor =
+ newFixedThreadPool(3,
+ groupedThreads("onos/ecord-sb-manager", "event-handler-%d"));
+
+ @Activate
+ public void activate() {
+ appId = coreService.registerApplication(PROVIDER_NAME);
+ // configRegistry.registerConfigFactory(diverConfigFactory);
+ configRegistry.registerConfigFactory(xosEndpointConfigFactory);
+ configService.addListener(configListener);
+ deviceProviderService = deviceProviderRegistry.register(this);
+ log.info("Started");
+ }
+
+ @Deactivate
+ public void deactivate() {
+ //configRegistry.unregisterConfigFactory(diverConfigFactory);
+ configRegistry.unregisterConfigFactory(xosEndpointConfigFactory);
+ configService.removeListener(configListener);
+ deviceProviderRegistry.unregister(this);
+ log.info("Stopped");
+ }
+
+ @Override
+ public ProviderId id() {
+ return PROVIDER_ID;
+ }
+
+ // ==== DeviceProvider ====
+ @Override
+ public void triggerProbe(DeviceId deviceId) {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public void roleChanged(DeviceId deviceId, MastershipRole newRole) {
+
+ }
+
+ @Override
+ public boolean isReachable(DeviceId deviceId) {
+ // TODO
+ return true;
+ }
+
+ @Override
+ public void changePortState(DeviceId deviceId, PortNumber portNumber,
+ boolean enable) {
+ // TODO
+ }
+
+ // ===== EcordDeviceProviderService =====
+ @Override
+ public void connectRemoteDevice(DomainVirtualDevice domainDevice) {
+ DomainId domainId = domainDevice.domainId();
+ DeviceId deviceId = domainDevice.deviceId();
+ advertiseDevice(deviceId, domainId);
+ // advertiseDevicePorts(deviceId, domainDevice.ports());
+ }
+
+ @Override
+ public void addOrUpdateRemotePorts(DomainId domainId, DeviceId deviceId,
+ List<PortDescription> ports) {
+ advertiseDevicePorts(deviceId, ports);
+ }
+
+ @Override
+ public void addRemotePort(DomainId domainId, DeviceId deviceId, Port newPort) {
+ }
+
+ @Override
+ public void updateRemotePortState(DomainId domainId, DeviceId deviceId, Port port) {
+ // TODO
+ }
+
+ @Override
+ public void disconnectRemoteDevice(DomainId domainId, DeviceId deviceId) {
+ disconnectDevice(deviceId);
+ }
+
+ @Override
+ public void removeRemotePort(DomainId domainId, DeviceId deviceId, PortNumber portNumber) {
+ // TODO
+ }
+
+ /**
+ * Notify the core system that a new domain device is on.
+ * @param deviceId remote device identifier
+ */
+ private void advertiseDevice(DeviceId deviceId, DomainId domainId) {
+ ChassisId chassisId = new ChassisId();
+ log.info("Notifying ecord virtual device...");
+ mastershipAdminService.setRole(clusterService.getLocalNode().id(), deviceId,
+ MastershipRole.MASTER);
+
+ // disable lldp for this virtual device and annotate it with the proper driver
+ // String driverKey = ecordDriverConfig.manufacturer() + "-" + ecordDriverConfig.hwVersion() + "-" +
+ // ecordDriverConfig.swVersion();
+ String driverKey = "onLab-1.0.0-1.0.0";
+ SparseAnnotations annotations = DefaultAnnotations.builder()
+ .set(NO_LLDP, "any")
+ .set(DOMAIN_ID, domainId.id())
+ .set(DRIVER, driverKey)
+ .build();
+
+ DeviceDescription deviceDescription = new DefaultDeviceDescription(
+ deviceId.uri(),
+ Device.Type.SWITCH,
+ "onLab", "1.0.0",
+ "1.0.0", UNKNOWN,
+ chassisId,
+ annotations);
+ deviceProviderService.deviceConnected(deviceId, deviceDescription);
+ }
+
+ /**
+ * Notify the core system of all ports of a domain device.
+ * @param deviceId device identifier
+ * @param portDescriptions description of ports
+ */
+ private void advertiseDevicePorts(DeviceId deviceId, List<PortDescription> portDescriptions) {
+ log.info("Notifying ecord virtual ports...");
+ deviceProviderService.updatePorts(deviceId, portDescriptions);
+ // addGlobalMefLtp(deviceId, portDescriptions);
+ notifyXoS(deviceId, portDescriptions);
+ }
+
+ private void disconnectDevice(DeviceId deviceId) {
+ deviceProviderService.deviceDisconnected(deviceId);
+ }
+
+ private void notifyXoS(DeviceId deviceId, List<PortDescription> portDescriptions) {
+ portDescriptions.forEach(port -> {
+ if (port.annotations().keys().contains(MEF_IF_TYPE)) {
+ Type type = Type.valueOf(
+ port.annotations().value(MEF_IF_TYPE));
+ ConnectPoint cp = new ConnectPoint(deviceId, port.portNumber());
+ switch (type) {
+ case UNI:
+ ObjectNode body = xoSHttpClient.mapper().createObjectNode();
+ body.put("tenant", port.annotations().value(DOMAIN_ID));
+ body.put("name", "UNI:" + cp.toString());
+ body.put("latlng", "[" + port.annotations().value(LATITUDE) + "," +
+ port.annotations().value(LONGITUDE) + "]");
+ body.put("cpe_id", cp.toString());
+ xoSHttpClient.restPut(body.toString(), cp.toString());
+ break;
+ case ENNI:
+
+ break;
+ case INNI:
+
+ break;
+ case GENERIC:
+
+ break;
+ default:
+ return;
+ }
+ }
+ });
+ }
+
+ /**
+ * Adds global {@link CarrierEthernetLogicalTerminationPoint}
+ * to {@link MetroOrchestrationService}.
+ *
+ * @param deviceId subject device ID
+ * @param portDescriptions list of notified ports
+ */
+ private void addGlobalMefLtp(DeviceId deviceId, List<PortDescription> portDescriptions) {
+ portDescriptions.forEach(port -> {
+ if (port.annotations().keys().contains(MEF_IF_TYPE)) {
+ Type type = Type.valueOf(
+ port.annotations().value(MEF_IF_TYPE));
+ CarrierEthernetNetworkInterface ni;
+ ConnectPoint cp = new ConnectPoint(deviceId, port.portNumber());
+ switch (type) {
+ case UNI:
+ ni = CarrierEthernetUni.builder()
+ .cp(cp)
+ .annotations(port.annotations())
+ .build();
+ break;
+ case ENNI:
+ ni = CarrierEthernetEnni.builder()
+ .cp(cp)
+ .build();
+ break;
+ case INNI:
+ ni = CarrierEthernetInni.builder()
+ .cp(cp)
+ .annotations(port.annotations())
+ .build();
+ break;
+ case GENERIC:
+ ni = new CarrierEthernetGenericNi(cp, null, port.annotations());
+ break;
+ default:
+ return;
+ }
+ metroOrchestrationService.addGlobalLtp(
+ new CarrierEthernetLogicalTerminationPoint(null, ni));
+ }
+ });
+ }
+
+ private void readXoSEndPointConfig() {
+ xoSHttpClient =
+ new XoSHttpClient(configRegistry.getConfig(appId, XosEndPointConfig.class).xos());
+ }
+
+ private void readDriverFromConfig() {
+ ecordDriverConfig =
+ configRegistry.getConfig(appId, EcordDriverConfig.class);
+ }
+
+ private class InternalConfigListener implements NetworkConfigListener {
+ @Override
+ public void event(NetworkConfigEvent event) {
+ if (!event.configClass().equals(EcordDriverConfig.class) ||
+ !event.configClass().equals(XosEndPointConfig.class)) {
+ return;
+ }
+ switch (event.type()) {
+ case CONFIG_ADDED:
+ log.info("Network configuration added");
+ if (event.configClass().equals(EcordDriverConfig.class)) {
+ eventExecutor.execute(VirtualDomainDeviceProvider.this::readDriverFromConfig);
+ } else {
+ eventExecutor.execute(VirtualDomainDeviceProvider.this::readXoSEndPointConfig);
+ }
+
+ break;
+ case CONFIG_UPDATED:
+ log.info("Network configuration updated");
+ if (event.configClass().equals(EcordDriverConfig.class)) {
+ eventExecutor.execute(VirtualDomainDeviceProvider.this::readDriverFromConfig);
+ } else {
+ eventExecutor.execute(VirtualDomainDeviceProvider.this::readXoSEndPointConfig);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ }
+}
diff --git a/global/virtualprovider/src/main/java/org/opencord/ce/global/virtualdomain/VirtualLinkProvider.java b/global/virtualprovider/src/main/java/org/opencord/ce/global/virtualdomain/VirtualLinkProvider.java
new file mode 100644
index 0000000..361d74c
--- /dev/null
+++ b/global/virtualprovider/src/main/java/org/opencord/ce/global/virtualdomain/VirtualLinkProvider.java
@@ -0,0 +1,218 @@
+/*
+ * Copyright 2017-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.opencord.ce.global.virtualdomain;
+
+import com.google.common.collect.Maps;
+import org.apache.commons.lang3.tuple.Pair;
+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.onosproject.core.CoreService;
+import org.onosproject.mastership.MastershipService;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.Link;
+import org.onosproject.net.MastershipRole;
+import org.onosproject.net.Port;
+import org.onosproject.net.SparseAnnotations;
+import org.onosproject.net.device.DeviceEvent;
+import org.onosproject.net.device.DeviceListener;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.link.DefaultLinkDescription;
+import org.onosproject.net.link.LinkDescription;
+import org.onosproject.net.link.LinkEvent;
+import org.onosproject.net.link.LinkListener;
+import org.onosproject.net.link.LinkProvider;
+import org.onosproject.net.link.LinkProviderRegistry;
+import org.onosproject.net.link.LinkProviderService;
+import org.onosproject.net.link.LinkService;
+import org.onosproject.net.provider.ProviderId;
+import org.opencord.ce.api.services.virtualprovider.LinkId;
+import org.slf4j.Logger;
+
+import java.util.Map;
+
+import static org.onosproject.net.Link.Type.INDIRECT;
+import static org.slf4j.LoggerFactory.getLogger;
+import static org.opencord.ce.global.virtualdomain.VirtualDomainDeviceProvider.PROVIDER_NAME;
+
+/**
+ * Domain interlinks provider.
+ */
+@Component(immediate = true)
+public class VirtualLinkProvider implements LinkProvider {
+ public static final ProviderId PROVIDER_ID = new ProviderId("domain", PROVIDER_NAME);
+ public static final String INTERLINK_ID = "interlinkId";
+ private final Logger log = getLogger(getClass());
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected CoreService coreService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected LinkProviderRegistry linkProviderRegistry;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected DeviceService deviceService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected LinkService linkService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected MastershipService mastershipService;
+
+ private final Map<LinkId, ConnectPoint> stagedInterlinks = Maps.newConcurrentMap();
+ private final Map<LinkId, Pair<ConnectPoint, ConnectPoint>>
+ committedInterlinks = Maps.newConcurrentMap();
+ private final DeviceListener deviceListener = new InternalDeviceListener();
+ private final LinkListener linkListener = new InternalLinkListener();
+
+ protected LinkProviderService linkProviderService;
+
+ @Activate
+ public void activate() {
+ coreService.registerApplication(PROVIDER_NAME);
+ linkProviderService = linkProviderRegistry.register(this);
+ deviceService.addListener(deviceListener);
+ linkService.addListener(linkListener);
+ log.info("Started");
+
+ }
+
+ @Deactivate
+ public void deactivate() {
+ linkProviderRegistry.unregister(this);
+ deviceService.removeListener(deviceListener);
+ linkService.removeListener(linkListener);
+ log.info("Stopped");
+ }
+
+
+ @Override
+ public ProviderId id() {
+ return PROVIDER_ID;
+ }
+
+ private void addInterLink(ConnectPoint point1, ConnectPoint point2, LinkId linkId) {
+ SparseAnnotations annotations = DefaultAnnotations.builder()
+ .set(INTERLINK_ID, linkId.id())
+ .build();
+ LinkDescription linkDescription = new DefaultLinkDescription(point1, point2,
+ INDIRECT, true, annotations);
+ linkProviderService.linkDetected(linkDescription);
+ }
+
+ private class InternalLinkListener implements LinkListener {
+
+ @Override
+ public void event(LinkEvent event) {
+ Link link = event.subject();
+ switch (event.type()) {
+ case LINK_REMOVED:
+ if (link.annotations().keys().contains(INTERLINK_ID)) {
+ committedInterlinks.remove(LinkId.linkId(
+ link.annotations().value(INTERLINK_ID)
+ ));
+ }
+ case LINK_ADDED:
+ // not relevant for now
+ default:
+ }
+ }
+ }
+
+
+ private class InternalDeviceListener implements DeviceListener {
+ @Override
+ public boolean isRelevant(DeviceEvent event) {
+ return (event.type().equals(DeviceEvent.Type.PORT_ADDED) ||
+ event.type().equals(DeviceEvent.Type.PORT_REMOVED) ||
+ event.type().equals(DeviceEvent.Type.PORT_UPDATED)) &&
+ event.port().annotations().keys().contains(INTERLINK_ID);
+ }
+
+ @Override
+ public void event(DeviceEvent event) {
+
+ Port port = event.port();
+ DeviceId subjectDeviceId = event.subject().id();
+ LinkId linkId = LinkId.linkId(port.annotations().value(INTERLINK_ID));
+
+ switch (event.type()) {
+ case PORT_ADDED:
+ case PORT_UPDATED:
+ if (committedInterlinks.containsKey(linkId)) {
+ // !!!! ===== !!!! //
+ // committed interlinks cannot be subject to changes
+ // unless a port is removed.
+ // Possibly this is an error condition
+ log.info("notified interlinks cannot be subject to changes," +
+ "unless a port of the link is removed. Possibly this is" +
+ "an error condition");
+ return;
+ } else {
+ log.info("Adding virtual inter-links...");
+ if (stagedInterlinks.containsKey(linkId)) {
+ ConnectPoint point1 =
+ stagedInterlinks.get(linkId);
+ ConnectPoint point2 =
+ new ConnectPoint(subjectDeviceId, port.number());
+ if (subjectDeviceId.equals(point1.deviceId())) {
+ return;
+ }
+
+ committedInterlinks.put(linkId, Pair.of(point1, point2));
+ stagedInterlinks.remove(linkId);
+
+ // only the master instance of the destination link can notify the link
+ if (mastershipService.getLocalRole(point2.deviceId())
+ .equals(MastershipRole.MASTER)) {
+ addInterLink(point1, point2, linkId);
+ }
+ if (mastershipService.getLocalRole(point1.deviceId())
+ .equals(MastershipRole.MASTER)) {
+ addInterLink(point2, point1, linkId);
+ }
+ } else {
+ stagedInterlinks.put(linkId,
+ new ConnectPoint(subjectDeviceId, port.number()));
+ }
+ }
+ break;
+ case PORT_REMOVED:
+ if (committedInterlinks.containsKey(linkId)) {
+ Pair<ConnectPoint, ConnectPoint> points =
+ committedInterlinks.get(linkId);
+ committedInterlinks.remove(linkId);
+ if (points.getLeft().deviceId().equals(subjectDeviceId)) {
+ linkProviderService.linksVanished(points.getLeft());
+ stagedInterlinks.put(linkId, points.getRight());
+ } else {
+ linkProviderService.linksVanished(points.getRight());
+ stagedInterlinks.put(linkId, points.getLeft());
+ }
+ } else if (stagedInterlinks.containsKey(linkId)) {
+ stagedInterlinks.remove(linkId);
+ }
+ break;
+ default:
+ }
+ }
+ }
+}
diff --git a/global/virtualprovider/src/main/java/org/opencord/ce/global/virtualdomain/XoSHttpClient.java b/global/virtualprovider/src/main/java/org/opencord/ce/global/virtualdomain/XoSHttpClient.java
new file mode 100644
index 0000000..1d72b40
--- /dev/null
+++ b/global/virtualprovider/src/main/java/org/opencord/ce/global/virtualdomain/XoSHttpClient.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2017-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.opencord.ce.global.virtualdomain;
+
+import com.fasterxml.jackson.databind.SerializationFeature;
+import org.glassfish.jersey.client.ClientProperties;
+import org.onosproject.rest.AbstractWebResource;
+import org.slf4j.Logger;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import static java.net.HttpURLConnection.HTTP_OK;
+import static org.slf4j.LoggerFactory.getLogger;
+import static org.opencord.ce.global.virtualdomain.config.XosEndPointConfig.XosEndPoint;
+
+/**
+ * Implementation of REST client for XOS Metro-net service.
+ */
+public class XoSHttpClient extends AbstractWebResource {
+ protected final Logger log = getLogger(getClass());
+
+ private static final int DEFAULT_TIMEOUT_MS = 2000;
+
+ private XosEndPoint xosEndPoint;
+ private final Client client = ClientBuilder.newClient();
+
+
+ public XoSHttpClient(XosEndPoint xosEndPoint) {
+ this.xosEndPoint = xosEndPoint;
+
+ client.property(ClientProperties.CONNECT_TIMEOUT, DEFAULT_TIMEOUT_MS);
+ client.property(ClientProperties.READ_TIMEOUT, DEFAULT_TIMEOUT_MS);
+ mapper().enable(SerializationFeature.INDENT_OUTPUT);
+ }
+
+ public void restPut(String body, String cpeId) {
+ WebTarget webTarget = client.target("http://" + xosEndPoint.ipAddress().toString() +
+ xosEndPoint.resource() + "/" + cpeId);
+ Response response;
+ response = webTarget.request(MediaType.APPLICATION_JSON)
+ .put(Entity.entity(body, MediaType.APPLICATION_JSON));
+ try {
+ if (response.getStatus() != HTTP_OK) {
+ log.warn("Failed to put resource {}", xosEndPoint.resource());
+ }
+ } catch (javax.ws.rs.ProcessingException e) {
+ log.error("Javax process exception in XoSClientHttp: {}", e.getMessage());
+ }
+ }
+}
diff --git a/global/virtualprovider/src/main/java/org/opencord/ce/global/virtualdomain/config/EcordDriverConfig.java b/global/virtualprovider/src/main/java/org/opencord/ce/global/virtualdomain/config/EcordDriverConfig.java
new file mode 100644
index 0000000..1077993
--- /dev/null
+++ b/global/virtualprovider/src/main/java/org/opencord/ce/global/virtualdomain/config/EcordDriverConfig.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2017-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.opencord.ce.global.virtualdomain.config;
+
+import org.onosproject.core.ApplicationId;
+import org.onosproject.net.config.Config;
+
+/**
+ * ICONA driver configuration class.
+ */
+public class EcordDriverConfig extends Config<ApplicationId> {
+
+ private static final String MANUFACTURER = "manufacturer";
+ private static final String SW_VERSION = "swVersion";
+ private static final String HW_VERSION = "hwVersion";
+
+
+ public String manufacturer() {
+ return object.get(MANUFACTURER).asText();
+ }
+
+ public String swVersion() {
+ return object.get(SW_VERSION).asText();
+ }
+
+ public String hwVersion() {
+ return object.get(HW_VERSION).asText();
+ }
+
+}
diff --git a/global/virtualprovider/src/main/java/org/opencord/ce/global/virtualdomain/config/XosEndPointConfig.java b/global/virtualprovider/src/main/java/org/opencord/ce/global/virtualdomain/config/XosEndPointConfig.java
new file mode 100644
index 0000000..df0c59e
--- /dev/null
+++ b/global/virtualprovider/src/main/java/org/opencord/ce/global/virtualdomain/config/XosEndPointConfig.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2017-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.opencord.ce.global.virtualdomain.config;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.onlab.packet.IpAddress;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.net.config.Config;
+
+/**
+ * Global XoS endpoint.
+ */
+public class XosEndPointConfig extends Config<ApplicationId> {
+ private static final String USERNAME = "username";
+ private static final String PASSWD = "password";
+ private static final String XOS = "xos";
+ private static final String ADDRESS = "address";
+ private static final String RESOURCE = "resource";
+
+ public XosEndPoint xos() {
+ JsonNode xosNode = object.path(XOS);
+ IpAddress ipAddress = IpAddress.valueOf(xosNode.get(ADDRESS).asText());
+ String username = xosNode.get(USERNAME).asText();
+ String password = xosNode.get(PASSWD).asText();
+ String resource = xosNode.get(RESOURCE).asText();
+ return new XosEndPoint(ipAddress, username, password, resource);
+ }
+
+ public static class XosEndPoint {
+ private IpAddress ipAddress;
+ private String username;
+ private String password;
+ private String resource;
+
+ public XosEndPoint(IpAddress ipAddress, String username,
+ String password, String resource) {
+ this.ipAddress = ipAddress;
+ this.username = username;
+ this.password = password;
+ this.resource = resource;
+ }
+
+ public IpAddress ipAddress() {
+ return ipAddress;
+ }
+
+ public String username() {
+ return username;
+ }
+
+ public String password() {
+ return password;
+ }
+
+ public String resource() {
+ return resource;
+ }
+ }
+
+}
diff --git a/global/virtualprovider/src/main/java/org/opencord/ce/global/virtualdomain/config/package-info.java b/global/virtualprovider/src/main/java/org/opencord/ce/global/virtualdomain/config/package-info.java
new file mode 100644
index 0000000..62fbacc
--- /dev/null
+++ b/global/virtualprovider/src/main/java/org/opencord/ce/global/virtualdomain/config/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-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.
+ */
+
+/**
+ * Configuration classes.
+ */
+package org.opencord.ce.global.virtualdomain.config;
\ No newline at end of file
diff --git a/global/virtualprovider/src/main/java/org/opencord/ce/global/virtualdomain/package-info.java b/global/virtualprovider/src/main/java/org/opencord/ce/global/virtualdomain/package-info.java
new file mode 100644
index 0000000..c71407e
--- /dev/null
+++ b/global/virtualprovider/src/main/java/org/opencord/ce/global/virtualdomain/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-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 for domain topology provider.
+ */
+package org.opencord.ce.global.virtualdomain;
\ No newline at end of file
diff --git a/local/bigswitch/pom.xml b/local/bigswitch/pom.xml
new file mode 100644
index 0000000..f11c4a6
--- /dev/null
+++ b/local/bigswitch/pom.xml
@@ -0,0 +1,100 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2017-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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.opencord.ce</groupId>
+ <artifactId>local</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>bigswitch</artifactId>
+ <packaging>bundle</packaging>
+
+ <description>Big switch abstraction topology</description>
+
+ <properties>
+ <onos.app.name>org.opencord.ce.local.bigswitch</onos.app.name>
+ <onos.app.title>E-CORD Carrier Ethernet bigswitch abstraction</onos.app.title>
+ <onos.app.url>http://opencord.org</onos.app.url>
+ <onos.version>1.10.6</onos.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-core-serializers</artifactId>
+ <version>${onos.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-cli</artifactId>
+ <version>${onos.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.karaf.shell</groupId>
+ <artifactId>org.apache.karaf.shell.console</artifactId>
+ <version>3.0.5</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.scr.annotations</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+ <repositories>
+ <repository>
+ <id>snapshots</id>
+ <url>https://oss.sonatype.org/content/repositories/snapshots</url>
+ <releases><enabled>false</enabled></releases>
+ </repository>
+ </repositories>
+
+ <pluginRepositories>
+ <pluginRepository>
+ <id>snapshots</id>
+ <url>https://oss.sonatype.org/content/repositories/snapshots</url>
+ <releases><enabled>false</enabled></releases>
+ </pluginRepository>
+ </pluginRepositories>
+
+</project>
diff --git a/local/bigswitch/src/main/java/org/opencord/ce/local/bigswitch/BigSwitchEvent.java b/local/bigswitch/src/main/java/org/opencord/ce/local/bigswitch/BigSwitchEvent.java
new file mode 100644
index 0000000..54fac26
--- /dev/null
+++ b/local/bigswitch/src/main/java/org/opencord/ce/local/bigswitch/BigSwitchEvent.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2017-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.opencord.ce.local.bigswitch;
+
+import com.google.common.collect.ImmutableList;
+import org.onosproject.event.AbstractEvent;
+import org.onosproject.net.device.PortDescription;
+
+import java.util.List;
+
+
+// TODO probably Event subject should contain Device info.
+// e.g., (DeviceId, PortDescription)
+public class BigSwitchEvent extends AbstractEvent<BigSwitchEvent.Type, PortDescription> {
+ private List<PortDescription> allPorts;
+
+ public enum Type {
+
+ /**
+ * Signifies the Big Switch abstraction is created.
+ */
+ DEVICE_CREATED,
+
+ /**
+ * Signifies the Big Switch abstraction is finished.
+ */
+ DEVICE_REMOVED,
+
+ /**
+ * Signifies a port was added to the big switch.
+ */
+ PORT_ADDED,
+ /**
+ * Signifies a port was removed from the big switch.
+ */
+ PORT_REMOVED,
+ /**
+ * Signifies a port was updated in the big switch.
+ */
+ PORT_UPDATED
+ }
+
+ /**
+ * Creates a new big switch event.
+ *
+ * @param type event type
+ * @param subject the port description
+ * @param allPorts list of all switch ports
+ */
+ public BigSwitchEvent(Type type, PortDescription subject, List<PortDescription> allPorts) {
+ super(type, subject);
+ this.allPorts = allPorts;
+ }
+
+ /**
+ * Creates a new big switch event.
+ *
+ * @param type event type
+ * @param subject the port description
+ * @param allPorts list of all switch ports
+ * @param time occurence time
+ */
+ public BigSwitchEvent(Type type, PortDescription subject, List<PortDescription> allPorts,
+ long time) {
+ super(type, subject, time);
+ this.allPorts = allPorts;
+ }
+
+ /**
+ * Returns list of ports known by this instance object.
+ *
+ * @return list of all ports
+ */
+ public List<PortDescription> allPorts() {
+ return ImmutableList.copyOf(allPorts);
+ }
+}
diff --git a/local/bigswitch/src/main/java/org/opencord/ce/local/bigswitch/BigSwitchListener.java b/local/bigswitch/src/main/java/org/opencord/ce/local/bigswitch/BigSwitchListener.java
new file mode 100644
index 0000000..2738916
--- /dev/null
+++ b/local/bigswitch/src/main/java/org/opencord/ce/local/bigswitch/BigSwitchListener.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2017-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.opencord.ce.local.bigswitch;
+
+import org.onosproject.event.EventListener;
+
+/**
+ * Component to inform about big switch updates.
+ */
+public interface BigSwitchListener extends EventListener<BigSwitchEvent> {
+}
diff --git a/local/bigswitch/src/main/java/org/opencord/ce/local/bigswitch/BigSwitchManager.java b/local/bigswitch/src/main/java/org/opencord/ce/local/bigswitch/BigSwitchManager.java
new file mode 100644
index 0000000..4629295
--- /dev/null
+++ b/local/bigswitch/src/main/java/org/opencord/ce/local/bigswitch/BigSwitchManager.java
@@ -0,0 +1,409 @@
+/*
+ * Copyright 2017-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.opencord.ce.local.bigswitch;
+
+import com.google.common.base.Strings;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+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.Modified;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.Service;
+import org.onosproject.cfg.ComponentConfigService;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.onosproject.event.AbstractListenerManager;
+import org.onosproject.net.AnnotationKeys;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.Device;
+import org.onosproject.net.Port;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.config.ConfigFactory;
+import org.onosproject.net.config.NetworkConfigEvent;
+import org.onosproject.net.config.NetworkConfigListener;
+import org.onosproject.net.config.NetworkConfigRegistry;
+import org.onosproject.net.config.NetworkConfigService;
+import org.onosproject.net.device.DefaultPortDescription;
+import org.onosproject.net.device.DeviceEvent;
+import org.onosproject.net.device.DeviceListener;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.device.PortDescription;
+import org.onosproject.net.domain.DomainId;
+import org.onosproject.store.serializers.KryoNamespaces;
+import org.onosproject.store.service.AtomicCounter;
+import org.onosproject.store.service.ConsistentMap;
+import org.onosproject.store.service.Serializer;
+import org.onosproject.store.service.StorageService;
+import org.onosproject.store.service.Versioned;
+import org.opencord.ce.api.models.CarrierEthernetNetworkInterface;
+import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+
+import java.util.Dictionary;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Properties;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.stream.Collectors;
+
+import static org.onlab.util.Tools.get;
+import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY;
+import static org.opencord.ce.api.services.channel.Symbols.MEF_PORT_TYPE;
+import static org.opencord.ce.local.bigswitch.MefPortsConfig.INTERLINK_ID;
+import static org.opencord.ce.local.bigswitch.MefPortsConfig.MEF_PORTS;
+import static org.opencord.ce.local.bigswitch.MefPortsConfig.MefPortConfig;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Listens for edge and port changes in the underlying data path and
+ * exposes a big switch abstraction.
+ */
+@Component(immediate = true)
+@Service
+public class BigSwitchManager
+ extends AbstractListenerManager<BigSwitchEvent, BigSwitchListener>
+ implements BigSwitchService {
+ private static final Logger log = getLogger(BigSwitchManager.class);
+ private static final String APP_NAME = "org.opencord.ce.local.bigswitch";
+
+ public static final String DEFAULT_DOMAIN_ID = "local-domain";
+
+ private static final String PORT_MAP = "ecord-port-map";
+ private static final String PORT_COUNTER = "ecord-port-counter";
+ private static final Serializer SERIALIZER = Serializer.using(KryoNamespaces.API);
+ private ApplicationId appId;
+ private final NetworkConfigListener configListener = new InternalConfigListener();
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected ComponentConfigService componentConfigService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected CoreService coreService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected NetworkConfigRegistry configRegistry;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected DeviceService deviceService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected StorageService storageService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected NetworkConfigService networkConfigService;
+
+ private static final String DOMAIN_ID = "domainId";
+ @Property(name = DOMAIN_ID, value = DEFAULT_DOMAIN_ID, label = "Domain ID where this ONOS is running")
+ private String domainId = DEFAULT_DOMAIN_ID;
+
+ private final ExecutorService executorService =
+ Executors.newSingleThreadExecutor();
+
+ // MEF ports given by configuration
+ private static List<MefPortConfig> mefPortConfigs;
+
+ /**
+ * Holds the physical port to virtual port number mapping.
+ */
+ private ConsistentMap<ConnectPoint, Long> portMap;
+
+ // Counter for virtual port numbers
+ private AtomicCounter portCounter;
+
+ // TODO listen to portMap event and populate Cache to properly deal with
+ // TODO distributed deployment.
+ /**
+ * History of physical port to virtual port number mapping.
+ * Intended to avoid virtual port number explosion.
+ */
+ private LoadingCache<ConnectPoint, Long> p2vMap;
+
+ // TODO: Add other listeners once we decide what an edge really is
+ private DeviceListener deviceListener = new InternalDeviceListener();
+
+ private final ConfigFactory<ApplicationId, MefPortsConfig> configFactory =
+ new ConfigFactory<ApplicationId, MefPortsConfig>(APP_SUBJECT_FACTORY,
+ MefPortsConfig.class, MEF_PORTS, true) {
+ @Override
+ public MefPortsConfig createConfig() {
+ return new MefPortsConfig();
+ }
+ };
+
+ @Activate
+ public void activate() {
+ appId = coreService.registerApplication(APP_NAME);
+ componentConfigService.registerProperties(getClass());
+ configRegistry.registerConfigFactory(configFactory);
+ networkConfigService.addListener(configListener);
+ portMap = storageService.<ConnectPoint, Long>consistentMapBuilder()
+ .withName(PORT_MAP)
+ .withSerializer(SERIALIZER)
+ .build();
+ portCounter = storageService.atomicCounterBuilder()
+ .withName(PORT_COUNTER)
+ .withMeteringDisabled()
+ .build()
+ .asAtomicCounter();
+ p2vMap = CacheBuilder.newBuilder()
+ .build(CacheLoader.from(portCounter::getAndIncrement));
+
+ eventDispatcher.addSink(BigSwitchEvent.class, listenerRegistry);
+ portCounter.compareAndSet(0, 1);
+ deviceService.addListener(deviceListener);
+ log.info("Started");
+ }
+
+ @Deactivate
+ public void deactivate() {
+ networkConfigService.removeListener(configListener);
+ configRegistry.unregisterConfigFactory(configFactory);
+ deviceService.removeListener(deviceListener);
+ componentConfigService.unregisterProperties(getClass(), false);
+ log.info("Stopped");
+ }
+
+ @Modified
+ public void modified(ComponentContext context) {
+ Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties();
+
+ String d = get(properties, DOMAIN_ID);
+ if (!Strings.isNullOrEmpty(d)) {
+ // TODO: signal new domain id to global
+ domainId = d;
+ }
+
+ log.info("Domain ID set to {}", domainId());
+ }
+
+ @Override
+ public List<PortDescription> getPorts() {
+ return portMap.keySet().stream()
+ .map(this::toVirtualPortDescription)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toList());
+ }
+
+ @Override
+ public PortNumber getPort(ConnectPoint port) {
+ // FIXME: error-check and seriously think about a better method definition.
+ Versioned<Long> portNo = portMap.get(port);
+ if (Versioned.valueOrNull(portNo) != null) {
+ return PortNumber.portNumber(portNo.value());
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public Optional<ConnectPoint> connectPointFromVirtPort(PortNumber portNumber) {
+ return portMap.asJavaMap().entrySet()
+ .stream()
+ .filter(entry -> Objects.equals(entry.getValue(), portNumber.toLong()))
+ .map(Map.Entry::getKey)
+ .findFirst();
+ }
+
+ @Override
+ public DomainId domainId() {
+ return DomainId.domainId(domainId);
+ }
+
+ /**
+ * Convert connect point to port description.
+ *
+ * @param cp connect point of physical port
+ * @return port description of virtual big switch port
+ */
+ private PortDescription toVirtualPortDescription(ConnectPoint cp) {
+ Port p = deviceService.getPort(cp.deviceId(), cp.port());
+ if (p == null) {
+ return null;
+ }
+ // copy annotation
+ DefaultAnnotations.Builder annot = DefaultAnnotations.builder();
+ p.annotations().keys()
+ .forEach(k -> annot.set(k, p.annotations().value(k)));
+ annot.set(DOMAIN_ID, domainId);
+ // add annotation about underlying physical connect-point
+ Device device = deviceService.getDevice(cp.deviceId());
+ if (device.annotations().keys()
+ .contains(AnnotationKeys.LONGITUDE) && device.annotations().keys()
+ .contains(AnnotationKeys.LATITUDE)) {
+ annot.set(AnnotationKeys.LONGITUDE,
+ device.annotations().value(AnnotationKeys.LONGITUDE));
+ annot.set(AnnotationKeys.LATITUDE, device.annotations().value(AnnotationKeys.LATITUDE));
+ }
+
+ // this is not really efficient...
+ Optional<MefPortConfig> mefPortConfig =
+ mefPortConfigs.stream().filter(item -> item.cp().equals(cp)).findFirst();
+ if (mefPortConfig.isPresent()) {
+ annot.set(MEF_PORT_TYPE, mefPortConfig.get().mefType().toString());
+ if (!mefPortConfig.get().interlinkId().id().equals("internal")) {
+ annot.set(INTERLINK_ID, mefPortConfig.get().interlinkId().id());
+ }
+ } else {
+ annot.set(MEF_PORT_TYPE, CarrierEthernetNetworkInterface.Type.GENERIC.toString());
+ }
+
+ Long vPortNo = Versioned.valueOrNull(portMap.get(cp));
+ if (vPortNo == null) {
+ return null;
+ }
+ PortNumber portNumber = PortNumber.portNumber(vPortNo);
+
+ return new DefaultPortDescription(portNumber, p.isEnabled(), p.type(),
+ p.portSpeed(), annot.build());
+ }
+
+ private void buildPorts() {
+ /*
+ edgePortService.getEdgePoints()
+ .forEach(cp -> {
+ log.info("DEBUG: {}", cp.toString());
+ if (isPortRelevant(cp)) {
+ portMap.put(cp, getVirtualPortNumber(cp));
+ }
+ });
+ */
+ deviceService.getDevices().forEach(device ->
+ deviceService.getPorts(device.id()).forEach(port -> {
+ ConnectPoint cp = new ConnectPoint(device.id(), port.number());
+ if (isPortRelevant(cp)) {
+ portMap.put(cp, getVirtualPortNumber(cp));
+ }
+ }
+ ));
+ }
+
+ private Long getVirtualPortNumber(ConnectPoint cp) {
+ return p2vMap.getUnchecked(cp);
+ }
+
+ private void readConfig() {
+ mefPortConfigs = configRegistry.getConfig(appId, MefPortsConfig.class).mefPortConfigs();
+
+ if (mefPortConfigs != null) {
+ buildPorts();
+ log.info("Notifying Bigswitch presence..");
+ if (portMap.size() > 0) {
+ post(new BigSwitchEvent(BigSwitchEvent.Type.DEVICE_CREATED, null, getPorts()));
+ }
+ }
+ }
+
+ private class InternalDeviceListener implements DeviceListener {
+ @Override
+ public boolean isRelevant(DeviceEvent event) {
+ // Only listen for real devices
+ return !event.subject().type().equals(Device.Type.VIRTUAL) &&
+ (event.type().equals(DeviceEvent.Type.PORT_ADDED) ||
+ event.type().equals(DeviceEvent.Type.PORT_UPDATED) ||
+ event.type().equals(DeviceEvent.Type.PORT_REMOVED));
+ }
+
+ @Override
+ public void event(DeviceEvent event) {
+ log.debug("Device event {} {} {}", event.subject(), event.port(), event.type());
+ ConnectPoint cp = new ConnectPoint(event.subject().id(), event.port().number());
+ if (!isPortRelevant(cp)) {
+ return;
+ }
+ BigSwitchEvent.Type bigSwitchEvent = null;
+
+ switch (event.type()) {
+ // Ignore most of these for now
+ case DEVICE_ADDED:
+ case DEVICE_AVAILABILITY_CHANGED:
+ case DEVICE_REMOVED:
+ case DEVICE_SUSPENDED:
+ case DEVICE_UPDATED:
+ case PORT_ADDED:
+ portMap.put(cp, getVirtualPortNumber(cp));
+ bigSwitchEvent = BigSwitchEvent.Type.PORT_ADDED;
+ break;
+ case PORT_REMOVED:
+ portMap.remove(cp, getVirtualPortNumber(cp));
+ bigSwitchEvent = BigSwitchEvent.Type.PORT_REMOVED;
+ break;
+ case PORT_STATS_UPDATED:
+ break;
+ case PORT_UPDATED:
+ bigSwitchEvent = BigSwitchEvent.Type.PORT_UPDATED;
+ // Update if state of existing edge changed
+ break;
+ default:
+ break;
+
+ }
+ if (bigSwitchEvent != null && portMap.containsKey(cp) && mefPortConfigs != null) {
+ PortDescription descr = toVirtualPortDescription(cp);
+ if (descr != null) {
+ post(new BigSwitchEvent(bigSwitchEvent,
+ descr, getPorts()));
+ }
+ }
+ }
+ }
+
+ private class InternalConfigListener implements NetworkConfigListener {
+
+ @Override
+ public void event(NetworkConfigEvent event) {
+ if (!event.configClass().equals(MefPortsConfig.class)) {
+ return;
+ }
+ switch (event.type()) {
+ case CONFIG_ADDED:
+ log.info("Network configuration added");
+ executorService.execute(BigSwitchManager.this::readConfig);
+ break;
+ case CONFIG_UPDATED:
+ log.info("Network configuration updated");
+ executorService.execute(BigSwitchManager.this::readConfig);
+ break;
+ case CONFIG_REMOVED:
+ // TODO
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ private boolean isPortRelevant(ConnectPoint cp) {
+ if (mefPortConfigs == null) {
+ return false;
+ }
+ for (MefPortConfig portConfig : mefPortConfigs) {
+ if (portConfig.cp().equals(cp)) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
diff --git a/local/bigswitch/src/main/java/org/opencord/ce/local/bigswitch/BigSwitchService.java b/local/bigswitch/src/main/java/org/opencord/ce/local/bigswitch/BigSwitchService.java
new file mode 100644
index 0000000..02f82de
--- /dev/null
+++ b/local/bigswitch/src/main/java/org/opencord/ce/local/bigswitch/BigSwitchService.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2017-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.opencord.ce.local.bigswitch;
+
+
+import org.onosproject.event.ListenerService;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.device.PortDescription;
+import org.onosproject.net.domain.DomainId;
+
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * Service to interact with big switch abstraction.
+ */
+public interface BigSwitchService extends ListenerService<BigSwitchEvent, BigSwitchListener> {
+ /**
+ * Gets list of big switch ports.
+ *
+ * @return list of port descriptions
+ */
+ List<PortDescription> getPorts();
+
+ /**
+ * Gets the big switch port mapped to the physical port.
+ *
+ * @param port the physical port
+ * @return virtual port number
+ */
+ PortNumber getPort(ConnectPoint port);
+
+
+ /**
+ * Gets the local connect point mapped to the specified virtual port number.
+ * @param portNumber virtual port number
+ * @return optional local-site connect point
+ */
+ Optional<ConnectPoint> connectPointFromVirtPort(PortNumber portNumber);
+
+ /**
+ * Returns the local domain ID of this bigswitch.
+ *
+ * @return domain ID
+ */
+ DomainId domainId();
+}
+
diff --git a/local/bigswitch/src/main/java/org/opencord/ce/local/bigswitch/MefPortsConfig.java b/local/bigswitch/src/main/java/org/opencord/ce/local/bigswitch/MefPortsConfig.java
new file mode 100644
index 0000000..3932acb
--- /dev/null
+++ b/local/bigswitch/src/main/java/org/opencord/ce/local/bigswitch/MefPortsConfig.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2017-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.opencord.ce.local.bigswitch;
+
+import org.onosproject.core.ApplicationId;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.config.Config;
+import org.opencord.ce.api.models.CarrierEthernetNetworkInterface;
+import org.opencord.ce.api.services.virtualprovider.LinkId;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.opencord.ce.api.services.channel.Symbols.MEF_PORT_TYPE;
+import static org.opencord.ce.api.models.CarrierEthernetNetworkInterface.Type;
+
+/**
+ * See config-samples/ecord-local-config.json.
+ */
+public class MefPortsConfig extends Config<ApplicationId> {
+ private final Logger log = LoggerFactory.getLogger(getClass());
+ public static final String MEF_PORTS = "mefPorts";
+ public static final String CONNECT_POINT = "connectPoint";
+ public static final String INTERLINK_ID = "interlinkId";
+
+ public List<MefPortConfig> mefPortConfigs() {
+ List<MefPortConfig> mefPortConfigs = new ArrayList<>();
+ array.forEach(item -> mefPortConfigs.add(new MefPortConfig(
+ ConnectPoint.deviceConnectPoint(item.path(CONNECT_POINT).asText()),
+ CarrierEthernetNetworkInterface.Type.valueOf(item.path(MEF_PORT_TYPE).asText()),
+ LinkId.linkId(item.path(INTERLINK_ID).isMissingNode() ? "internal" :
+ item.path(INTERLINK_ID).asText())
+ )));
+ return mefPortConfigs;
+ }
+
+ public static class MefPortConfig {
+ private ConnectPoint cp;
+ private CarrierEthernetNetworkInterface.Type mefType;
+ private LinkId interlinkId;
+
+ public MefPortConfig(ConnectPoint cp, Type mefType,
+ LinkId interlinkId) {
+ this.cp = cp;
+ this.mefType = mefType;
+ this.interlinkId = interlinkId;
+ }
+
+ public ConnectPoint cp() {
+ return cp;
+ }
+
+ public Type mefType() {
+ return mefType;
+ }
+
+ public LinkId interlinkId() {
+ return interlinkId;
+ }
+ }
+}
diff --git a/local/bigswitch/src/main/java/org/opencord/ce/local/bigswitch/cli/BigSwitchPortsCommand.java b/local/bigswitch/src/main/java/org/opencord/ce/local/bigswitch/cli/BigSwitchPortsCommand.java
new file mode 100644
index 0000000..22af7db
--- /dev/null
+++ b/local/bigswitch/src/main/java/org/opencord/ce/local/bigswitch/cli/BigSwitchPortsCommand.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2017-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.opencord.ce.local.bigswitch.cli;
+
+import org.apache.karaf.shell.commands.Command;
+import org.onosproject.cli.AbstractShellCommand;
+import org.opencord.ce.local.bigswitch.BigSwitchService;
+
+/**
+ * Command to list the ports of the bigswitch.
+ */
+@Command(scope = "onos", name = "bigswitch-ports",
+ description = "Lists the bigswitch ports")
+public class BigSwitchPortsCommand extends AbstractShellCommand {
+
+ @Override
+ public void execute() {
+ BigSwitchService bigSwitchService = get(BigSwitchService.class);
+
+ bigSwitchService.getPorts().forEach(
+ portDescription -> print(portDescription.toString())
+ );
+ }
+}
diff --git a/local/bigswitch/src/main/java/org/opencord/ce/local/bigswitch/cli/ConnectPointFromVirtPortCmd.java b/local/bigswitch/src/main/java/org/opencord/ce/local/bigswitch/cli/ConnectPointFromVirtPortCmd.java
new file mode 100644
index 0000000..b94fec5
--- /dev/null
+++ b/local/bigswitch/src/main/java/org/opencord/ce/local/bigswitch/cli/ConnectPointFromVirtPortCmd.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2017-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.opencord.ce.local.bigswitch.cli;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.net.PortNumber;
+import org.opencord.ce.local.bigswitch.BigSwitchService;
+
+/**
+ * Returns the connect point associated to the specified port number of the bigswitch.
+ */
+@Command(scope = "onos", name = "bigswitch-port", description = "Returns the connect point" +
+ "associated with the specified virtual port of the bigswitch")
+public class ConnectPointFromVirtPortCmd extends AbstractShellCommand {
+
+ @Argument(index = 1, name = "port",
+ description = "Virtual bigswitch port",
+ required = true, multiValued = false)
+ String port = "0";
+
+
+ @Override
+ public void execute() {
+ BigSwitchService bigSwitchService = get(BigSwitchService.class);
+ print(bigSwitchService.connectPointFromVirtPort(PortNumber.fromString(port)).toString());
+
+ }
+}
diff --git a/local/bigswitch/src/main/java/org/opencord/ce/local/bigswitch/cli/package-info.java b/local/bigswitch/src/main/java/org/opencord/ce/local/bigswitch/cli/package-info.java
new file mode 100644
index 0000000..194fb9f
--- /dev/null
+++ b/local/bigswitch/src/main/java/org/opencord/ce/local/bigswitch/cli/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-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.
+ */
+
+/**
+ * CLI command to explore the bigswitch ports.
+ */
+package org.opencord.ce.local.bigswitch.cli;
\ No newline at end of file
diff --git a/local/bigswitch/src/main/java/org/opencord/ce/local/bigswitch/package-info.java b/local/bigswitch/src/main/java/org/opencord/ce/local/bigswitch/package-info.java
new file mode 100644
index 0000000..ca91d6a
--- /dev/null
+++ b/local/bigswitch/src/main/java/org/opencord/ce/local/bigswitch/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-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.
+ */
+
+/**
+ * Big switch abstraction package.
+ */
+package org.opencord.ce.local.bigswitch;
\ No newline at end of file
diff --git a/local/bigswitch/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/local/bigswitch/src/main/resources/OSGI-INF/blueprint/shell-config.xml
new file mode 100644
index 0000000..2db5ad1
--- /dev/null
+++ b/local/bigswitch/src/main/resources/OSGI-INF/blueprint/shell-config.xml
@@ -0,0 +1,26 @@
+<!--
+ ~ Copyright 2017-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.
+ -->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+
+ <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
+ <command>
+ <action class="org.opencord.ce.local.bigswitch.cli.BigSwitchPortsCommand"/>
+ </command>
+ <command>
+ <action class="org.opencord.ce.local.bigswitch.cli.ConnectPointFromVirtPortCmd"/>
+ </command>
+ </command-bundle>
+</blueprint>
diff --git a/local/ce-fabric/features.xml b/local/ce-fabric/features.xml
new file mode 100644
index 0000000..83ba135
--- /dev/null
+++ b/local/ce-fabric/features.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+ ~ Copyright 2017-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.
+ -->
+<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}">
+ <feature name="${project.artifactId}" version="${project.version}"
+ description="${project.description}">
+ <bundle>mvn:com.google.code.gson/gson/2.6.2</bundle>
+ </feature>
+</features>
diff --git a/local/ce-fabric/pom.xml b/local/ce-fabric/pom.xml
new file mode 100644
index 0000000..0e3bb75
--- /dev/null
+++ b/local/ce-fabric/pom.xml
@@ -0,0 +1,111 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2017-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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.opencord.ce</groupId>
+ <artifactId>local</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>fabric</artifactId>
+ <packaging>bundle</packaging>
+
+ <description>CORD application for Carrier Ethernet Service</description>
+
+ <properties>
+ <onos.app.name>org.opencord.ce.local.fabric</onos.app.name>
+ <onos.version>1.10.6</onos.version>
+ <onos.app.title>E-CORD Central Office fabric config</onos.app.title>
+ <onos.app.url>http://opencord.org</onos.app.url>
+ <onos.app.requires>org.opencord.ce.local.bigswitch</onos.app.requires>
+ <onos.app.requires>org.opencord.ce.local.channel.http</onos.app.requires>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.opencord.ce</groupId>
+ <artifactId>bigswitch</artifactId>
+ <version>${parent.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ <version>2.6.2</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-api</artifactId>
+ <version>${onos.version}</version>
+ <classifier>tests</classifier>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onlab-osgi</artifactId>
+ <version>${onos.version}</version>
+ <classifier>tests</classifier>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.media</groupId>
+ <artifactId>jersey-media-json-jackson</artifactId>
+ <version>2.25.1</version>
+ </dependency>
+ </dependencies>
+
+ <repositories>
+ <repository>
+ <id>snapshots</id>
+ <url>https://oss.sonatype.org/content/repositories/snapshots</url>
+ <releases><enabled>false</enabled></releases>
+ </repository>
+ </repositories>
+
+ <pluginRepositories>
+ <pluginRepository>
+ <id>snapshots</id>
+ <url>https://oss.sonatype.org/content/repositories/snapshots</url>
+ <releases><enabled>false</enabled></releases>
+ </pluginRepository>
+ </pluginRepositories>
+
+</project>
diff --git a/local/ce-fabric/src/main/java/org/opencord/ce/local/fabric/CarrierEthernetFabricConfig.java b/local/ce-fabric/src/main/java/org/opencord/ce/local/fabric/CarrierEthernetFabricConfig.java
new file mode 100644
index 0000000..2d8a9c1
--- /dev/null
+++ b/local/ce-fabric/src/main/java/org/opencord/ce/local/fabric/CarrierEthernetFabricConfig.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2017-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.opencord.ce.local.fabric;
+
+import org.onlab.packet.IpAddress;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.config.Config;
+
+/**
+ * Configuration for single switch CORD fabric manager for Carrier Ethernet services.
+ */
+public class CarrierEthernetFabricConfig extends Config<ApplicationId> {
+ private static final int DEFAULT_PORT = 8181;
+ private static final String DEFAULT_USERNAME = "onos";
+ private static final String DEFAULT_PASSWORD = "rocks";
+
+ private static final String PUBLIC_IP = "publicIp";
+ private static final String PORT = "port";
+ private static final String USERNAME = "username";
+ private static final String PASSWORD = "password";
+ private static final String DEVICE_ID = "deviceId";
+
+ @Override
+ public boolean isValid() {
+ return hasOnlyFields(PUBLIC_IP, PORT, USERNAME, PASSWORD, DEVICE_ID) &&
+ publicIp() != null &&
+ deviceId() != null;
+ }
+
+ public IpAddress publicIp() {
+ String ip = get(PUBLIC_IP, null);
+ try {
+ return IpAddress.valueOf(ip);
+ } catch (IllegalArgumentException e) {
+ return null;
+ }
+ }
+
+ public Integer port() {
+ String port = get(PORT, String.valueOf(DEFAULT_PORT));
+ try {
+ return Integer.valueOf(port);
+ } catch (NumberFormatException e) {
+ return DEFAULT_PORT;
+ }
+ }
+
+ public String username() {
+ return get(USERNAME, String.valueOf(DEFAULT_USERNAME));
+ }
+
+ public String password() {
+ return get(PASSWORD, String.valueOf(DEFAULT_PASSWORD));
+ }
+
+ public DeviceId deviceId() {
+ String did = get(DEVICE_ID, null);
+ try {
+ return DeviceId.deviceId(did);
+ } catch (IllegalArgumentException e) {
+ return null;
+ }
+ }
+}
diff --git a/local/ce-fabric/src/main/java/org/opencord/ce/local/fabric/CarrierEthernetFabricManager.java b/local/ce-fabric/src/main/java/org/opencord/ce/local/fabric/CarrierEthernetFabricManager.java
new file mode 100644
index 0000000..249031b
--- /dev/null
+++ b/local/ce-fabric/src/main/java/org/opencord/ce/local/fabric/CarrierEthernetFabricManager.java
@@ -0,0 +1,312 @@
+/*
+ * Copyright 2017-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.opencord.ce.local.fabric;
+
+import com.google.gson.JsonArray;
+import com.google.gson.JsonObject;
+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.glassfish.jersey.client.ClientConfig;
+import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
+import org.onlab.packet.IpAddress;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.config.ConfigFactory;
+import org.onosproject.net.config.NetworkConfigEvent;
+import org.onosproject.net.config.NetworkConfigListener;
+import org.onosproject.net.config.NetworkConfigRegistry;
+import org.opencord.ce.api.models.CarrierEthernetForwardingConstruct;
+import org.opencord.ce.api.models.CarrierEthernetNetworkInterface;
+import org.opencord.ce.api.models.CarrierEthernetUni;
+import org.opencord.ce.api.models.EvcConnId;
+import org.opencord.ce.api.services.MetroNetworkVirtualNodeService;
+import org.opencord.ce.local.bigswitch.BigSwitchService;
+import org.slf4j.Logger;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+
+import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Manages a single switch CORD fabric for Carrier Ethernet services.
+ *
+ * Receives forwarding constructs from global orchestrator,
+ * and generates VLAN cross connect configuration for the
+ * ONOS fabric controller.
+ *
+ * No resources are allocated so only the node forwarding API is implemented.
+ */
+@Component(immediate = true)
+@Service
+public class CarrierEthernetFabricManager implements MetroNetworkVirtualNodeService {
+ private static final Logger log = getLogger(CarrierEthernetFabricManager.class);
+ private static final String APP_NAME = "org.opencord.ce.local.fabric";
+ private static final String APPS = "apps";
+ private static final String SEGMENT_ROUTING = "org.onosproject.segmentrouting";
+ private static final String XCONNECT = "xconnect";
+ private static final String VLAN = "vlan";
+ private static final String PORTS = "ports";
+ private static final String NAME = "name";
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected BigSwitchService bigSwitchService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected CoreService coreService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected NetworkConfigRegistry cfgService;
+
+ private final InternalConfigListener cfgListener = new InternalConfigListener();
+
+ private final ConfigFactory<ApplicationId, CarrierEthernetFabricConfig> configFactory =
+ new ConfigFactory<ApplicationId, CarrierEthernetFabricConfig>(APP_SUBJECT_FACTORY,
+ CarrierEthernetFabricConfig.class, "segmentrouting_ctl", false) {
+ @Override
+ public CarrierEthernetFabricConfig createConfig() {
+ return new CarrierEthernetFabricConfig();
+ }
+ };
+
+ private ApplicationId appId;
+ // TODO: use distributed maps via storage service
+ private Set<CarrierEthernetForwardingConstruct> forwardingConstructs = new LinkedHashSet<>();
+ private Map<EvcConnId, ConnectPoint> eePorts = new HashMap<>();
+ private Map<EvcConnId, ConnectPoint> upstreamPorts = new HashMap<>();
+ private IpAddress publicIp;
+ private Integer port;
+ private String username;
+ private String password;
+ private DeviceId deviceId;
+
+ @Activate
+ protected void activate() {
+ appId = coreService.registerApplication(APP_NAME);
+ cfgService.addListener(cfgListener);
+ cfgService.registerConfigFactory(configFactory);
+ cfgListener.doUpdate(cfgService.getConfig(appId, CarrierEthernetFabricConfig.class));
+ log.info("Started");
+ }
+
+ @Deactivate
+ protected void deactivate() {
+ cfgService.removeListener(cfgListener);
+ cfgService.unregisterConfigFactory(configFactory);
+ log.info("Stopped");
+ }
+
+ @Override
+ public void setNodeForwarding(CarrierEthernetForwardingConstruct fc,
+ CarrierEthernetNetworkInterface srcNi,
+ Set<CarrierEthernetNetworkInterface> dstNiSet) {
+ addCrossconnect(fc, srcNi, dstNiSet);
+ postToSegmentRouting(buildConfig());
+ }
+
+ @Override
+ public void createBandwidthProfileResources(CarrierEthernetForwardingConstruct fc, CarrierEthernetUni uni) {
+ // No resources are allocated on the fabric
+ return;
+ }
+
+ @Override
+ public void applyBandwidthProfileResources(CarrierEthernetForwardingConstruct fc, CarrierEthernetUni uni) {
+ // No resources are allocated on the fabric
+ return;
+ }
+
+ @Override
+ public void removeBandwidthProfileResources(CarrierEthernetForwardingConstruct fc, CarrierEthernetUni uni) {
+ // No resources are allocated on the fabric
+ return;
+ }
+
+ @Override
+ public void removeAllForwardingResources(EvcConnId fcId) {
+ removeCrossconnect(fcId);
+ postToSegmentRouting(buildConfig());
+ }
+
+ /**
+ * Adds a fabric cross connect based on given Carrier Ethernet service.
+ *
+ * @param fc forwarding construct
+ * @param srcNi source network interface
+ * @param dstNiSet set of destination network interfaces
+ */
+ public void addCrossconnect(CarrierEthernetForwardingConstruct fc,
+ CarrierEthernetNetworkInterface srcNi,
+ Set<CarrierEthernetNetworkInterface> dstNiSet) {
+ // Store fc and extract physical fabric ports
+ Optional<ConnectPoint> eePort = bigSwitchService.connectPointFromVirtPort(srcNi.cp().port());
+ // Assume only a single upstream port is used, so we select randomly from set
+ CarrierEthernetNetworkInterface dstNi = dstNiSet.iterator().next();
+ Optional<ConnectPoint> upstreamPort = (dstNi == null) ? Optional.empty() :
+ bigSwitchService.connectPointFromVirtPort(dstNi.cp().port());
+ if (!eePort.isPresent() || !upstreamPort.isPresent()) {
+ log.error("Failed to install node forwarding, missing fabric ports: EE {} - upstream {}",
+ eePort, upstreamPort);
+ return;
+ } else {
+ forwardingConstructs.add(fc);
+ eePorts.put(fc.id(), eePort.get());
+ upstreamPorts.put(fc.id(), upstreamPort.get());
+ }
+ }
+
+ /**
+ * Removes a fabric cross connect based on given forwarding construct.
+ *
+ * @param fcId forwarding construct id
+ */
+ public void removeCrossconnect(EvcConnId fcId) {
+ for (Iterator<CarrierEthernetForwardingConstruct> i = forwardingConstructs.iterator(); i.hasNext();) {
+ CarrierEthernetForwardingConstruct fc = i.next();
+ if (fcId.equals(fc.id())) {
+ forwardingConstructs.remove(fc);
+ break;
+ }
+ }
+ eePorts.remove(fcId);
+ upstreamPorts.remove(fcId);
+ }
+
+
+ /**
+ * All VLAN cross connects are rebuilt and pushed out since ONOS network config does not support updates.
+ *
+ * @return JSON with cross connect configuration for segment routing app
+ */
+ public JsonObject buildConfig() {
+ JsonArray xconnects = new JsonArray();
+ forwardingConstructs.stream()
+ .map(fc -> json(fc))
+ .forEach(fc -> xconnects.add(fc));
+
+ JsonObject dpid = new JsonObject();
+ dpid.add(deviceId.toString(), xconnects);
+
+ JsonObject xconnect = new JsonObject();
+ xconnect.add(XCONNECT, dpid);
+
+ JsonObject appName = new JsonObject();
+ appName.add(SEGMENT_ROUTING, xconnect);
+
+ JsonObject config = new JsonObject();
+ config.add(APPS, appName);
+
+ return config;
+ }
+
+ /**
+ * Execute REST POST to segment routing app with given VLAN cross connect config.
+ *
+ * @param json fabric VLAN cross connect configuration in json form
+ */
+ public void postToSegmentRouting(JsonObject json) {
+ // Setup credentials
+ HttpAuthenticationFeature feature = HttpAuthenticationFeature.basicBuilder()
+ .nonPreemptive()
+ .credentials(username, password)
+ .build();
+ ClientConfig cfg = new ClientConfig();
+ cfg.register(feature);
+ Client client = ClientBuilder.newClient(cfg);
+
+ // Build URL and perform post
+ WebTarget target = client.target("http://" + publicIp + ":" + port + "/onos/v1/network/configuration/");
+ Response response = target.request().post(Entity.entity(json, MediaType.APPLICATION_JSON_TYPE));
+ response.close();
+ }
+
+ /**
+ * Build fabric config json from forwarding construct.
+ *
+ * Example VLAN cross connect configuration for fabric
+ * "apps": {
+ * "org.onosproject.segmentrouting": {
+ * "xconnect": {
+ * "of:0000000000000001": [{
+ * "vlan": 10,
+ * "ports": [5, 73],
+ * "name": "OLT1"
+ * }]
+ * }
+ * }
+ * }
+ */
+ private JsonObject json(CarrierEthernetForwardingConstruct fc) {
+ JsonObject jo = new JsonObject();
+ jo.addProperty(VLAN, fc.vlanId().toShort());
+
+ // First port is EE -> fabric, second is fabric -> upstream / CO egress
+ JsonArray ports = new JsonArray();
+ // FIXME: need to be more careful of nulls here
+ ports.add(eePorts.get(fc.id()).port().toLong());
+ ports.add(upstreamPorts.get(fc.id()).port().toLong());
+ jo.add(PORTS, ports);
+
+ jo.addProperty(NAME, fc.id().id());
+
+ return jo;
+ }
+
+ private class InternalConfigListener implements NetworkConfigListener {
+ private void doUpdate(CarrierEthernetFabricConfig cfg) {
+ if (cfg == null) {
+ log.error("Fabric config for VLAN xconnect missing");
+ return;
+ }
+
+ publicIp = cfg.publicIp();
+ port = cfg.port();
+ username = cfg.username();
+ password = cfg.password();
+ deviceId = cfg.deviceId();
+ log.info("Reconfigured");
+ }
+
+ @Override
+ public void event(NetworkConfigEvent event) {
+ if ((event.type() == NetworkConfigEvent.Type.CONFIG_ADDED ||
+ event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED) &&
+ event.configClass().equals(CarrierEthernetFabricConfig.class)) {
+
+ if (event.config().isPresent()) {
+ doUpdate((CarrierEthernetFabricConfig) event.config().get());
+ }
+ }
+ }
+ }
+}
diff --git a/local/ce-fabric/src/main/java/org/opencord/ce/local/fabric/package-info.java b/local/ce-fabric/src/main/java/org/opencord/ce/local/fabric/package-info.java
new file mode 100644
index 0000000..0b030a4
--- /dev/null
+++ b/local/ce-fabric/src/main/java/org/opencord/ce/local/fabric/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-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.
+ */
+
+/**
+ * Single switch CORD fabric support for Carrier Ethernet services.
+ */
+package org.opencord.ce.local.fabric;
\ No newline at end of file
diff --git a/local/ce-fabric/src/test/java/org.opencord.ce.local.fabric/CarrierEthernetFabricManagerTest.java b/local/ce-fabric/src/test/java/org.opencord.ce.local.fabric/CarrierEthernetFabricManagerTest.java
new file mode 100644
index 0000000..cabcb77
--- /dev/null
+++ b/local/ce-fabric/src/test/java/org.opencord.ce.local.fabric/CarrierEthernetFabricManagerTest.java
@@ -0,0 +1,243 @@
+/*
+ * Copyright 2017-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.opencord.ce.local.fabric;
+
+import com.google.common.collect.Sets;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.onlab.junit.TestUtils;
+import org.onlab.osgi.ServiceDirectory;
+import org.onlab.osgi.TestServiceDirectory;
+import org.onlab.packet.VlanId;
+import org.onosproject.core.CoreServiceAdapter;
+import org.onosproject.event.AbstractListenerManager;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.config.NetworkConfigRegistryAdapter;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.device.DeviceServiceAdapter;
+import org.onosproject.net.device.PortDescription;
+import org.onosproject.net.domain.DomainId;
+import org.opencord.ce.api.models.CarrierEthernetConnection;
+import org.opencord.ce.api.models.CarrierEthernetEnni;
+import org.opencord.ce.api.models.CarrierEthernetForwardingConstruct;
+import org.opencord.ce.api.models.CarrierEthernetInni;
+import org.opencord.ce.api.models.CarrierEthernetLogicalTerminationPoint;
+import org.opencord.ce.api.models.CarrierEthernetNetworkInterface;
+import org.opencord.ce.api.models.CarrierEthernetUni;
+import org.opencord.ce.api.models.EvcConnId;
+import org.opencord.ce.local.bigswitch.BigSwitchEvent;
+import org.opencord.ce.local.bigswitch.BigSwitchListener;
+import org.opencord.ce.local.bigswitch.BigSwitchService;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Unit tests for {@link CarrierEthernetFabricManager}.
+ */
+public class CarrierEthernetFabricManagerTest {
+
+ private CarrierEthernetFabricManager target;
+ private static ServiceDirectory original;
+ private static TestServiceDirectory directory;
+
+ private CarrierEthernetLogicalTerminationPoint ltpSrc;
+ private CarrierEthernetLogicalTerminationPoint ltpDst;
+ // Physical connect points
+ private static ConnectPoint srcUniCp = ConnectPoint.deviceConnectPoint("netconf:10.0.0.10/1");
+ private ConnectPoint dstUniCp = ConnectPoint.deviceConnectPoint("netconf:10.0.0.20/1");
+ private ConnectPoint inniPhyCp = ConnectPoint.deviceConnectPoint("of:0000000000000001/1");
+ private ConnectPoint enni1PhyCp = ConnectPoint.deviceConnectPoint("of:0000000000000001/2");
+ private ConnectPoint enni2PhyCp = ConnectPoint.deviceConnectPoint("of:0000000000000001/3");
+ // Bigswitch (logical) connect points
+ private ConnectPoint inniBsCp = ConnectPoint.deviceConnectPoint("domain:0000000000000001/1");
+ private ConnectPoint enni1BsCp = ConnectPoint.deviceConnectPoint("domain:0000000000000001/2");
+ private ConnectPoint enni2BsCp = ConnectPoint.deviceConnectPoint("domain:0000000000000001/3");
+ // Carrier Ethernet models
+ private CarrierEthernetForwardingConstruct fc1;
+ private CarrierEthernetForwardingConstruct fc2;
+ private CarrierEthernetNetworkInterface srcUni;
+ private CarrierEthernetNetworkInterface dstUni;
+ private CarrierEthernetNetworkInterface inni;
+ private CarrierEthernetNetworkInterface enni1;
+ private CarrierEthernetNetworkInterface enni2;
+
+ private DeviceId deviceId = DeviceId.deviceId("of:0000000000000001");
+ private static VlanId vlan1 = VlanId.vlanId((short) 100);
+ private static VlanId vlan2 = VlanId.vlanId((short) 200);
+
+ @BeforeClass
+ public static void setUpBaseConfigClass() throws TestUtils.TestUtilsException {
+ directory = new TestServiceDirectory();
+ directory.add(DeviceService.class, new DeviceServiceAdapter(Collections.emptyList()));
+ original = TestUtils.getField(CarrierEthernetNetworkInterface.class, "serviceDirectory");
+ TestUtils.setField(CarrierEthernetNetworkInterface.class, "serviceDirectory", directory);
+ }
+
+ @AfterClass
+ public static void tearDownBaseConfigClass() throws TestUtils.TestUtilsException {
+ TestUtils.setField(CarrierEthernetNetworkInterface.class, "serviceDirectory", original);
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ // Initialize the fabric manager
+ target = new CarrierEthernetFabricManager();
+ target.bigSwitchService = new TestBigSwitchService();
+ target.cfgService = new NetworkConfigRegistryAdapter();
+ target.coreService = new CoreServiceAdapter();
+
+ // Build UNIs
+ srcUni = CarrierEthernetUni.builder()
+ .cp(srcUniCp)
+ .build();
+ dstUni = CarrierEthernetUni.builder()
+ .cp(dstUniCp)
+ .build();
+ ltpSrc = new CarrierEthernetLogicalTerminationPoint("srcUni", srcUni);
+ ltpDst = new CarrierEthernetLogicalTerminationPoint("dstUni", dstUni);
+
+ // Build FC connecting UNIs
+ fc1 = CarrierEthernetForwardingConstruct.builder()
+ .cfgId("test1")
+ .id(EvcConnId.of("test1"))
+ .type(CarrierEthernetConnection.Type.POINT_TO_POINT)
+ .ltpSet(Sets.newHashSet(ltpSrc, ltpDst))
+ .build();
+ fc1.setVlanId(vlan1);
+ fc2 = CarrierEthernetForwardingConstruct.builder()
+ .cfgId("test2")
+ .id(EvcConnId.of("test2"))
+ .type(CarrierEthernetConnection.Type.POINT_TO_POINT)
+ .ltpSet(Sets.newHashSet(ltpSrc, ltpDst))
+ .build();
+ fc2.setVlanId(vlan2);
+ inni = CarrierEthernetInni.builder()
+ .cp(inniBsCp)
+ .build();
+ enni1 = CarrierEthernetEnni.builder()
+ .cp(enni1BsCp)
+ .build();
+ enni2 = CarrierEthernetEnni.builder()
+ .cp(enni2BsCp)
+ .build();
+
+ target.activate();
+ }
+
+ @After
+ public void tearDown() {
+ target.deactivate();
+ }
+
+ @Test
+ public void testBuildConfig() {
+ TestUtils.setField(target, "deviceId", deviceId);
+ JsonParser parser = new JsonParser();
+ JsonObject json;
+ String expected;
+
+ // Add first fc
+ target.addCrossconnect(fc1, inni, Sets.newHashSet(enni1));
+ json = target.buildConfig();
+ expected =
+ "{\"apps\":{" +
+ "\"org.onosproject.segmentrouting\":{" +
+ "\"xconnect\":{" +
+ "\"of:0000000000000001\":[{" +
+ "\"vlan\":" + vlan1.toString() + "," +
+ "\"ports\":[1, 2]," +
+ "\"name\": \"" + fc1.id().id() + "\"}" +
+ "]}}}}";
+ assertEquals(json, parser.parse(expected).getAsJsonObject());
+
+ // Add second fc
+ target.addCrossconnect(fc2, inni, Sets.newHashSet(enni2));
+ json = target.buildConfig();
+ expected =
+ "{\"apps\":{" +
+ "\"org.onosproject.segmentrouting\":{" +
+ "\"xconnect\":{" +
+ "\"of:0000000000000001\":[{" +
+ "\"vlan\":" + vlan1.toString() + "," +
+ "\"ports\":[1, 2]," +
+ "\"name\": \"" + fc1.id().id() + "\"}," +
+ "{\"vlan\":" + vlan2.toString() + "," +
+ "\"ports\":[1, 3]," +
+ "\"name\": \"" + fc2.id().id() + "\"}" +
+ "]}}}}";
+ assertEquals(json, parser.parse(expected).getAsJsonObject());
+
+ // Remove first fc
+ target.removeCrossconnect(fc1.id());
+ json = target.buildConfig();
+ expected =
+ "{\"apps\":{" +
+ "\"org.onosproject.segmentrouting\":{" +
+ "\"xconnect\":{" +
+ "\"of:0000000000000001\":[{" +
+ "\"vlan\":" + vlan2.toString() + "," +
+ "\"ports\":[1, 3]," +
+ "\"name\": \"" + fc2.id().id() + "\"}" +
+ "]}}}}";
+ assertEquals(json, parser.parse(expected).getAsJsonObject());
+ }
+
+ private class TestBigSwitchService
+ extends AbstractListenerManager<BigSwitchEvent, BigSwitchListener>
+ implements BigSwitchService {
+
+ @Override
+ public List<PortDescription> getPorts() {
+ return null;
+ }
+
+ @Override
+ public PortNumber getPort(ConnectPoint port) {
+ return null;
+ }
+
+ @Override
+ public Optional<ConnectPoint> connectPointFromVirtPort(PortNumber portNumber) {
+ if (portNumber.toLong() == 1) {
+ return Optional.of(inniPhyCp);
+ }
+ if (portNumber.toLong() == 2) {
+ return Optional.of(enni1PhyCp);
+ }
+ if (portNumber.toLong() == 3) {
+ return Optional.of(enni2PhyCp);
+ }
+
+ return Optional.empty();
+ }
+
+ @Override
+ public DomainId domainId() {
+ return null;
+ }
+ }
+}
diff --git a/local/ce-transport/pom.xml b/local/ce-transport/pom.xml
new file mode 100644
index 0000000..13203ba
--- /dev/null
+++ b/local/ce-transport/pom.xml
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2017-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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.opencord.ce</groupId>
+ <artifactId>local</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>transport</artifactId>
+ <packaging>bundle</packaging>
+
+ <description>Transport network provisioner of Carrier Ethernet service</description>
+
+ <properties>
+ <onos.app.name>org.opencord.ce.local.transport</onos.app.name>
+ <onos.version>1.10.6</onos.version>
+ <onos.app.url>http://opencord.org</onos.app.url>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+ <repositories>
+ <repository>
+ <id>snapshots</id>
+ <url>https://oss.sonatype.org/content/repositories/snapshots</url>
+ <releases><enabled>false</enabled></releases>
+ </repository>
+ </repositories>
+
+ <pluginRepositories>
+ <pluginRepository>
+ <id>snapshots</id>
+ <url>https://oss.sonatype.org/content/repositories/snapshots</url>
+ <releases><enabled>false</enabled></releases>
+ </pluginRepository>
+ </pluginRepositories>
+
+</project>
diff --git a/local/ce-transport/src/main/java/org/opencord/ce/local/transport/package-info.java b/local/ce-transport/src/main/java/org/opencord/ce/local/transport/package-info.java
new file mode 100644
index 0000000..6da5261
--- /dev/null
+++ b/local/ce-transport/src/main/java/org/opencord/ce/local/transport/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-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.
+ */
+
+/**
+ * Transport network for Carrier Ethernet package.
+ */
+package org.opencord.ce.local.transport;
\ No newline at end of file
diff --git a/local/ce-vee/pom.xml b/local/ce-vee/pom.xml
new file mode 100644
index 0000000..5ac2ee6
--- /dev/null
+++ b/local/ce-vee/pom.xml
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2017-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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.opencord.ce</groupId>
+ <artifactId>local</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>vee</artifactId>
+ <packaging>bundle</packaging>
+ <version>1.0.0-SNAPSHOT</version>
+
+ <description>Virtual Ethernet Edge service for CORD</description>
+
+ <properties>
+ <onos.app.name>org.opencord.ce.local.vee</onos.app.name>
+ <onos.app.title>E-CORD Ethernet Edge app</onos.app.title>
+ <onos.app.url>http://opencord.org</onos.app.url>
+ <onos.app.requires>org.opencord.ce.local.bigswitch</onos.app.requires>
+ <onos.app.requires>org.opencord.ce.local.channel.http</onos.app.requires>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.opencord.ce</groupId>
+ <artifactId>bigswitch</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+ <repositories>
+ <repository>
+ <id>snapshots</id>
+ <url>https://oss.sonatype.org/content/repositories/snapshots</url>
+ <releases><enabled>false</enabled></releases>
+ </repository>
+ </repositories>
+
+ <pluginRepositories>
+ <pluginRepository>
+ <id>snapshots</id>
+ <url>https://oss.sonatype.org/content/repositories/snapshots</url>
+ <releases><enabled>false</enabled></releases>
+ </pluginRepository>
+ </pluginRepositories>
+
+</project>
diff --git a/local/ce-vee/src/main/java/org/opencord/ce/local/vee/VeeManager.java b/local/ce-vee/src/main/java/org/opencord/ce/local/vee/VeeManager.java
new file mode 100644
index 0000000..1ac2b21
--- /dev/null
+++ b/local/ce-vee/src/main/java/org/opencord/ce/local/vee/VeeManager.java
@@ -0,0 +1,730 @@
+/*
+ * Copyright 2017-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.opencord.ce.local.vee;
+
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.commons.lang3.tuple.Pair;
+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.EthType;
+import org.onlab.packet.Ethernet;
+import org.onlab.packet.VlanId;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.Link;
+import org.onosproject.net.Path;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.driver.Driver;
+import org.onosproject.net.driver.DriverService;
+import org.onosproject.net.flow.DefaultFlowRule;
+import org.onosproject.net.flow.DefaultTrafficSelector;
+import org.onosproject.net.flow.DefaultTrafficTreatment;
+import org.onosproject.net.flow.FlowRule;
+import org.onosproject.net.flow.FlowRuleService;
+import org.onosproject.net.flow.TrafficSelector;
+import org.onosproject.net.flow.TrafficTreatment;
+import org.onosproject.net.flow.criteria.Criteria;
+import org.onosproject.net.flow.criteria.Criterion;
+import org.onosproject.net.flow.instructions.Instruction;
+import org.onosproject.net.flow.instructions.Instructions;
+import org.onosproject.net.flow.instructions.L2ModificationInstruction;
+import org.onosproject.net.flowobjective.DefaultFilteringObjective;
+import org.onosproject.net.flowobjective.DefaultForwardingObjective;
+import org.onosproject.net.flowobjective.DefaultNextObjective;
+import org.onosproject.net.flowobjective.FilteringObjective;
+import org.onosproject.net.flowobjective.FlowObjectiveService;
+import org.onosproject.net.flowobjective.ForwardingObjective;
+import org.onosproject.net.flowobjective.NextObjective;
+import org.onosproject.net.flowobjective.Objective;
+import org.onosproject.net.link.LinkService;
+import org.onosproject.net.meter.Band;
+import org.onosproject.net.meter.DefaultBand;
+import org.onosproject.net.meter.DefaultMeterRequest;
+import org.onosproject.net.meter.Meter;
+import org.onosproject.net.meter.MeterId;
+import org.onosproject.net.meter.MeterRequest;
+import org.onosproject.net.meter.MeterService;
+import org.onosproject.net.topology.PathService;
+import org.opencord.ce.api.models.CarrierEthernetEnni;
+import org.opencord.ce.api.models.CarrierEthernetForwardingConstruct;
+import org.opencord.ce.api.models.CarrierEthernetGenericNi;
+import org.opencord.ce.api.models.CarrierEthernetInni;
+import org.opencord.ce.api.models.CarrierEthernetNetworkInterface;
+import org.opencord.ce.api.models.CarrierEthernetUni;
+import org.opencord.ce.api.models.EvcConnId;
+import org.opencord.ce.api.services.MetroNetworkVirtualNodeService;
+
+import org.opencord.ce.local.bigswitch.BigSwitchService;
+import org.slf4j.Logger;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+
+import static org.slf4j.LoggerFactory.getLogger;
+import static org.opencord.ce.api.models.CarrierEthernetNetworkInterface.Type;
+import static org.onosproject.net.DefaultEdgeLink.createEdgeLink;
+
+/**
+ * Class used to control Ethernet Edge nodes according to the OpenFlow (1.3 and above) protocol.
+ */
+@Component(immediate = true)
+@Service(value = MetroNetworkVirtualNodeService.class)
+public class VeeManager implements MetroNetworkVirtualNodeService {
+ private static final int PRIORITY = 50000;
+ public static final String APP_NAME = "org.opencord.ce.local.vee";
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected CoreService coreService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected FlowRuleService flowRuleService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected MeterService meterService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected FlowObjectiveService flowObjectiveService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected LinkService linkService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected BigSwitchService bigSwitchService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected PathService pathService;
+
+ // FIXME slightly better way to detect OF-DPA issues
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected DriverService drivers;
+
+ private final Logger log = getLogger(getClass());
+
+ private ApplicationId appId;
+
+ // FIXME: We don't need to store the submitted meters as we can get them from the service
+ private Map<EvcConnId, Set<Pair<DeviceId, MeterId>>> fcMeterMap =
+ new ConcurrentHashMap<>();
+ // Store submitted flow objects as the service does not allow query operations
+ private final Map<EvcConnId, LinkedList<Pair<DeviceId, Objective>>> flowObjectiveMap =
+ new ConcurrentHashMap<>();
+
+ private final Map<EvcConnId, DeviceId> eeDeviceMap = new ConcurrentHashMap<>();
+
+ @Activate
+ protected void activate() {
+ appId = coreService.registerApplication(APP_NAME);
+
+ // TODO: start packet intercept for untagged traffic?
+ log.info("Started");
+
+ // testCentec();
+ }
+
+ @Deactivate
+ protected void deactivate() {
+
+ log.info("Stopped");
+ }
+
+
+ @Override
+ public void setNodeForwarding(CarrierEthernetForwardingConstruct fc, CarrierEthernetNetworkInterface ingressNi,
+ Set<CarrierEthernetNetworkInterface> egressNiSet) {
+
+ log.info("DEBUG: setForwarding method called..");
+ if (ingressNi == null || egressNiSet.isEmpty()) {
+ log.error("There needs to be at least one ingress and one egress NI to set forwarding.");
+ return;
+ }
+
+ flowObjectiveMap.putIfAbsent(fc.id(), new LinkedList<>());
+
+ CarrierEthernetNetworkInterface realIngressNi;
+ Optional<ConnectPoint> optCp =
+ bigSwitchService.connectPointFromVirtPort(ingressNi.cp().port());
+ if (optCp.isPresent()) {
+ realIngressNi = buildLocalNi(optCp.get(), ingressNi);
+ } else {
+ log.warn("Virtual ingress interface does not map to a local connect point");
+ return;
+ }
+
+ // real <-> virtual
+ final Map<ConnectPoint, CarrierEthernetNetworkInterface> realEgressNi = new HashMap<>();
+ egressNiSet.forEach(egressNi -> {
+ Optional<ConnectPoint> opt =
+ bigSwitchService.connectPointFromVirtPort(egressNi.cp().port());
+ opt.ifPresent(connectPoint -> realEgressNi.put(connectPoint, egressNi));
+ });
+
+ // it is necessary to identify the number of egress devices in order to build the
+ // flow rules
+ Set<DeviceId> egressDevices = new HashSet<>();
+ realEgressNi.keySet().forEach(cp -> egressDevices.add(cp.deviceId()));
+
+ //for how it is made the CE app, egressNiSet contains only one item, but...
+ egressDevices.forEach(deviceId -> {
+ // group the egress NI per device
+ Set<CarrierEthernetNetworkInterface> perDeviceEgressNiSet = new HashSet<>();
+ realEgressNi.keySet().forEach(cp -> {
+ if (cp.deviceId().equals(deviceId)) {
+ perDeviceEgressNiSet.add(buildLocalNi(cp, realEgressNi.get(cp)));
+ }
+ });
+ // if the egress device ID is equal to the ingress --> install rules
+ if (deviceId.equals(realIngressNi.cp().deviceId())) {
+ createFlowObjectives(fc, realIngressNi,
+ perDeviceEgressNiSet);
+ } else {
+ Set<Path> paths = pathService.getPaths(realIngressNi.cp().deviceId(),
+ deviceId);
+ Path path;
+ // TODO: Select path in more sophisticated way and return null if any of the constraints cannot be met
+ path = paths.iterator().hasNext() ? paths.iterator().next() : null;
+ if (path == null) {
+ return;
+ }
+ // for each NI, add edge links ()
+ perDeviceEgressNiSet.forEach(egressNi -> {
+ List<Link> links = new ArrayList<>();
+ links.add(createEdgeLink(realIngressNi.cp(), true));
+ links.addAll(path.links());
+ links.add(createEdgeLink(egressNi.cp(), false));
+
+ HashMap<CarrierEthernetNetworkInterface, HashSet<CarrierEthernetNetworkInterface>>
+ ingressEgressNiMap = new HashMap<>();
+ populateIngressEgressNiMap(realIngressNi, egressNi, links, ingressEgressNiMap);
+ // Establish connectivity using the ingressEgressNiMap
+ ingressEgressNiMap.keySet().forEach(srcNi ->
+ createFlowObjectives(fc, srcNi, ingressEgressNiMap.get(srcNi)));
+ });
+ }
+ });
+ }
+
+ private void populateIngressEgressNiMap(CarrierEthernetNetworkInterface srcNi,
+ CarrierEthernetNetworkInterface dstNi,
+ List<Link> linkList,
+ HashMap<CarrierEthernetNetworkInterface,
+ HashSet<CarrierEthernetNetworkInterface>> ingressEgressNiMap
+ ) {
+ // FIXME: Fix the method - avoid generating GENERIC NIs if not needed
+ // Add the src and destination NIs as well as the associated Generic NIs
+ ingressEgressNiMap.putIfAbsent(srcNi, new HashSet<>());
+ // Add last hop entry only if srcNi, dstNi aren't on same device (in which case srcNi, ingressNi would coincide)
+ if (!srcNi.cp().deviceId().equals(dstNi.cp().deviceId())) {
+ // If srcNi, dstNi are not on the same device, create mappings to/from new GENERIC NIs
+ ingressEgressNiMap.get(srcNi).add(new CarrierEthernetGenericNi(linkList.get(1).src(), null));
+ CarrierEthernetGenericNi ingressNi =
+ new CarrierEthernetGenericNi(linkList.get(linkList.size() - 2).dst(), null);
+ ingressEgressNiMap.putIfAbsent(ingressNi, new HashSet<>());
+ ingressEgressNiMap.get(ingressNi).add(dstNi);
+ } else {
+ // If srcNi, dstNi are on the same device, this is the only mapping that will be created
+ ingressEgressNiMap.get(srcNi).add(dstNi);
+ }
+
+ // Go through the links and create/add the intermediate NIs
+ for (int i = 1; i < linkList.size() - 2; i++) {
+ CarrierEthernetGenericNi ingressNi = new CarrierEthernetGenericNi(linkList.get(i).dst(), null);
+ ingressEgressNiMap.putIfAbsent(ingressNi, new HashSet<>());
+ ingressEgressNiMap.get(ingressNi).add(new CarrierEthernetGenericNi(linkList.get(i + 1).src(), null));
+ }
+ }
+
+ private CarrierEthernetNetworkInterface buildLocalNi(ConnectPoint localCp, CarrierEthernetNetworkInterface
+ virtualNi) {
+ CarrierEthernetNetworkInterface ni;
+ switch (virtualNi.type()) {
+ case UNI:
+ CarrierEthernetUni tmpUni = (CarrierEthernetUni) virtualNi;
+ ni = CarrierEthernetUni.builder()
+ .cp(localCp)
+ .role(tmpUni.role())
+ .ceVlanId(tmpUni.ceVlanId())
+ .bwp(tmpUni.bwp())
+ .build();
+ break;
+ case ENNI:
+ CarrierEthernetEnni tmpEnni = (CarrierEthernetEnni) virtualNi;
+ ni = CarrierEthernetEnni.builder()
+ .cp(localCp)
+ .role(tmpEnni.role())
+ .sVlanId(tmpEnni.sVlanId())
+ .build();
+ break;
+ case INNI:
+ CarrierEthernetInni tmpInni = (CarrierEthernetInni) virtualNi;
+ ni = CarrierEthernetInni.builder()
+ .cp(localCp)
+ .role(tmpInni.role())
+ .sVlanId(tmpInni.sVlanId())
+ .build();
+ break;
+ case GENERIC:
+ ni = new CarrierEthernetGenericNi(localCp, null);
+ break;
+ default:
+ return null;
+ }
+ return ni;
+
+ }
+
+ /**
+ * Creates and submits FlowObjectives into the device vesting the role of Ethernet Edge.
+ *
+ * @param fc the FC representation
+ * @param ingressNi the ingress network interface
+ * @param egressNiSet the set of egress NIs
+ */
+ private void createFlowObjectives(CarrierEthernetForwardingConstruct fc, CarrierEthernetNetworkInterface ingressNi,
+ Set<CarrierEthernetNetworkInterface> egressNiSet) {
+ DeviceId deviceId = ingressNi.cp().deviceId();
+ PortNumber portNumber = ingressNi.cp().port();
+
+ /////////////////////////////////////////
+ // Prepare and submit filtering objective
+ /////////////////////////////////////////
+
+ FilteringObjective.Builder filterObjBuilder = DefaultFilteringObjective.builder()
+ .permit().fromApp(appId)
+ .withPriority(PRIORITY)
+ .withKey(Criteria.matchInPort(portNumber));
+
+ TrafficTreatment.Builder filterTreatmentBuilder = DefaultTrafficTreatment.builder();
+ // In general, nodes would match on the VLAN tag assigned to the EVC/FC
+ Criterion filterVlanIdCriterion = Criteria.matchVlanId(fc.vlanId());
+
+ if ((ingressNi.type().equals(CarrierEthernetNetworkInterface.Type.INNI))
+ || (ingressNi.type().equals(CarrierEthernetNetworkInterface.Type.ENNI))) {
+ // TODO: Check TPID? Also: Is is possible to receive untagged pkts at an INNI/ENNI?
+ // Source node of an FC should match on S-TAG if it's an INNI/ENNI
+ filterVlanIdCriterion = Criteria.matchVlanId(ingressNi.sVlanId());
+ // Translate S-TAG to the one used in the current FC
+ filterTreatmentBuilder.setVlanId(fc.vlanId());
+ } else if (ingressNi.type().equals(CarrierEthernetNetworkInterface.Type.UNI)) {
+ // Source node of an FC should match on CE-VLAN ID (if present) if it's a UNI
+ filterVlanIdCriterion = Criteria.matchVlanId(ingressNi.ceVlanId());
+ // Obtain related Meter (if it exists) and add it in the treatment in case it may be used
+ if (fcMeterMap.get(fc.id()) != null && !fcMeterMap.get(fc.id()).isEmpty()) {
+ fcMeterMap.get(fc.id()).forEach(devMeterPair -> {
+ if (devMeterPair.getLeft().equals(deviceId)) {
+ filterTreatmentBuilder.meter(devMeterPair.getRight());
+ }
+ });
+ }
+ // If a CE-VLAN-ID exists on the incoming packet then push an S-TAG of current FC on top
+ // otherwise push it on as a C-tag
+ if (ingressNi.ceVlanId() != null && ingressNi.ceVlanId() != VlanId.NONE) {
+ filterTreatmentBuilder.pushVlan(EthType.EtherType.QINQ.ethType()).setVlanId(fc.vlanId());
+ } else {
+ filterTreatmentBuilder.pushVlan().setVlanId(fc.vlanId());
+ }
+ }
+
+ filterObjBuilder.addCondition(filterVlanIdCriterion);
+
+
+
+ // Do not add meta if there are no instructions (i.e. if not first)
+ if (!(ingressNi.type().equals(Type.GENERIC))) {
+ filterObjBuilder.withMeta(filterTreatmentBuilder.build());
+ }
+
+ flowObjectiveService.filter(deviceId, filterObjBuilder.add());
+ flowObjectiveMap.get(fc.id()).addFirst(Pair.of(deviceId, filterObjBuilder.add()));
+
+ ////////////////////////////////////////////////////
+ // Prepare and submit next and forwarding objectives
+ ////////////////////////////////////////////////////
+
+ TrafficSelector.Builder fwdSelectorBuilder = DefaultTrafficSelector.builder()
+ .matchVlanId(fc.vlanId())
+ .matchInPort(portNumber);
+
+ if (isOfDpa(deviceId)) {
+ // workaround for OF-DPA
+ fwdSelectorBuilder.matchEthType(Ethernet.TYPE_IPV4);
+ }
+
+ TrafficSelector fwdSelector = fwdSelectorBuilder.build();
+
+ Integer nextId = flowObjectiveService.allocateNextId();
+
+ NextObjective.Type nextType = egressNiSet.size() == 1 ?
+ NextObjective.Type.SIMPLE : NextObjective.Type.BROADCAST;
+
+ // Setting higher priority to fwd/next objectives to bypass filter in case of match conflict in OVS switches
+ NextObjective.Builder nextObjectiveBuider = DefaultNextObjective.builder()
+ .fromApp(appId)
+ .makePermanent()
+ .withType(nextType)
+ .withPriority(PRIORITY + 1)
+ .withMeta(fwdSelector)
+ .withId(nextId);
+
+ egressNiSet.forEach(egressNi -> {
+ // TODO: Check if ingressNi and egressNi are on the same device?
+ TrafficTreatment.Builder nextTreatmentBuilder = DefaultTrafficTreatment.builder();
+ // If last NI in FC is not UNI,
+ // keep the existing S-TAG - it will be translated at the entrance of the next FC
+ if (egressNi.type().equals(CarrierEthernetNetworkInterface.Type.UNI)) {
+ nextTreatmentBuilder.popVlan();
+ }
+ Instruction outInstruction = Instructions.createOutput(egressNi.cp().port());
+ nextTreatmentBuilder.add(outInstruction);
+ nextObjectiveBuider.addTreatment(nextTreatmentBuilder.build());
+ });
+
+ NextObjective nextObjective = nextObjectiveBuider.add();
+
+ // Setting higher priority to fwd/next objectives to bypass filter in case of match conflict in OVS switches
+ ForwardingObjective forwardingObjective = DefaultForwardingObjective.builder()
+ .fromApp(appId)
+ .makePermanent()
+ .withFlag(ForwardingObjective.Flag.VERSATILE)
+ .withPriority(PRIORITY + 1)
+ .withSelector(fwdSelector)
+ .nextStep(nextId)
+ .add();
+
+ flowObjectiveService.next(ingressNi.cp().deviceId(), nextObjective);
+ // Add all NextObjectives at the end of the list so that they will be removed last
+ flowObjectiveMap.get(fc.id()).addLast(Pair.of(ingressNi.cp().deviceId(), nextObjective));
+
+ flowObjectiveService.forward(ingressNi.cp().deviceId(), forwardingObjective);
+ flowObjectiveMap.get(fc.id()).addFirst(Pair.of(ingressNi.cp().deviceId(), forwardingObjective));
+ }
+
+ @Override
+ public void createBandwidthProfileResources(CarrierEthernetForwardingConstruct fc, CarrierEthernetUni uni) {
+ log.info("Creating BW profile...{}", uni.toString());
+ // Create meters and add them to global MeterId map
+ Set<Pair<DeviceId, MeterId>> meters;
+
+ DeviceId deviceId = getEEDevice(fc, uni);
+
+ if (fcMeterMap.containsKey(fc.id())) {
+ meters = fcMeterMap.get(fc.id());
+ } else {
+ meters = new HashSet<>();
+ if (deviceId == null) {
+ // no meters
+ return;
+ }
+ }
+ meters.addAll(submitMeters(fc, uni, deviceId));
+ fcMeterMap.put(fc.id(), meters);
+ }
+
+ private boolean isOfDpa(DeviceId deviceId) {
+ Driver driver = drivers.getDriver(deviceId);
+ return driver != null &&
+ driver.swVersion().contains("OF-DPA");
+ }
+
+ // Maybe we still need this method to later modify the QoS profile of an FC
+ @Override
+ public void applyBandwidthProfileResources(CarrierEthernetForwardingConstruct fc, CarrierEthernetUni uni) {
+ log.info("Applying BW profile...");
+
+ DeviceId deviceId = eeDeviceMap.get(fc.id());
+ if (deviceId == null) {
+ log.warn("Trying to apply bandwidth profile rules" +
+ "to not existing device/meters map");
+ return;
+ }
+
+ // Do not apply meters to NETCONF-controlled switches here since they should have been applied in the pipeline
+ // FIXME: Is there a better way to check this?
+ if (deviceId.uri().getScheme().equals("netconf")) {
+ return;
+ }
+
+ // Do not apply meters to OFDPA 2.0 switches since they are not currently supported
+ if (isOfDpa(deviceId)) {
+ return;
+ }
+
+ // Get installed flows with the same appId/deviceId with IN_PORT = UNI port which push the FC vlanId
+ List<FlowRule> flowRuleList =
+ StreamSupport.stream(flowRuleService.getFlowEntries(deviceId).spliterator(), false)
+ .filter(flowRule -> flowRule.appId() == appId.id())
+ .collect(Collectors.toList());
+ //&& getPushedVlanFromTreatment(flowRule.treatment()).equals(fc.vlanId()))
+
+
+ // Apply meters to flows
+ for (FlowRule flowRule : flowRuleList) {
+ // Need to add to the flow the meters associated with the same device
+ Set<Pair<DeviceId, MeterId>> deviceMeterIdSet = new HashSet<>();
+
+ if (fcMeterMap.get(fc.id()) != null && !fcMeterMap.get(fc.id()).isEmpty()) {
+ fcMeterMap.get(fc.id()).forEach(devMeterPair -> {
+ if (devMeterPair.getLeft().equals(flowRule.deviceId())) {
+ deviceMeterIdSet.add(devMeterPair);
+ }
+ });
+ }
+ // Modify and submit flow rule only if there are meters to add
+ if (!deviceMeterIdSet.isEmpty()) {
+ log.info("Applying metered flow rules...");
+ FlowRule newFlowRule = addMetersToFlowRule(flowRule, deviceMeterIdSet);
+ flowRuleService.applyFlowRules(newFlowRule);
+ }
+ }
+ }
+
+ private VlanId getPushedVlanFromTreatment(TrafficTreatment treatment) {
+ boolean pushVlan = false;
+ VlanId pushedVlan = null;
+ for (Instruction instruction : treatment.allInstructions()) {
+ if (instruction.type().equals(Instruction.Type.L2MODIFICATION)) {
+ L2ModificationInstruction l2ModInstr = (L2ModificationInstruction) instruction;
+ if (l2ModInstr.subtype().equals(L2ModificationInstruction.L2SubType.VLAN_PUSH)) {
+ pushVlan = true;
+ } else if (l2ModInstr.subtype().equals(L2ModificationInstruction.L2SubType.VLAN_ID) && pushVlan) {
+ pushedVlan = ((L2ModificationInstruction.ModVlanIdInstruction) instruction).vlanId();
+ }
+ }
+ }
+ return pushedVlan != null ? pushedVlan : VlanId.NONE;
+ }
+
+
+ /**
+ * Creates and submits a meter with the required bands for a UNI.
+ *
+ * @param uni the UNI descriptor
+ * @return set of meter ids of the meters created
+ */
+ private Set<Pair<DeviceId, MeterId>> submitMeters(CarrierEthernetForwardingConstruct fc,
+ CarrierEthernetUni uni, DeviceId deviceId) {
+ Set<Pair<DeviceId, MeterId>> meters = new HashSet<>();
+
+ uni.bwps().forEach(bwp -> {
+ log.info("bwp: {}", bwp.toString());
+
+ // KB_PER_SECOND
+ long longCir = (long) (bwp.cir().bps() / 8000);
+ long longEir = (long) (bwp.eir().bps() / 8000);
+ log.info("longCir: {}", longCir);
+ log.info("longEir: {}", longEir);
+
+ MeterRequest.Builder meterRequestBuilder;
+ Meter meter;
+ Band.Builder bandBuilder;
+
+ Set<Band> bandSet = new HashSet<>();
+
+ // If EIR is zero do not create the REMARK meter
+ /* === Centec v350 supports only DROP type! ===
+ if (longEir != 0) {
+ log.info("Enter here..");
+ // Mark frames that exceed CIR as Best Effort
+ bandBuilder = DefaultBand.builder()
+ .ofType(Band.Type.REMARK)
+ .withRate(longCir)
+ .dropPrecedence((short) 0);
+
+ if (bwp.cbs() != 0) {
+ bandBuilder.burstSize(bwp.cbs());
+ }
+
+ bandSet.add(bandBuilder.build());
+ }
+ */
+
+ // If CIR is zero do not create the DROP meter
+ if (longCir != 0) {
+ // Drop all frames that exceed CIR + EIR
+ bandBuilder = DefaultBand.builder()
+ .ofType(Band.Type.DROP)
+ .withRate(longCir + longEir);
+
+ if (bwp.cbs() != 0 || bwp.ebs() != 0) {
+ // FIXME: Use CBS and EBS correctly according to MEF specs
+ bandBuilder.burstSize(bwp.cbs() + bwp.ebs());
+ }
+
+ bandSet.add(bandBuilder.build());
+ }
+
+ // Create meter only if at least one band was created
+ if (!bandSet.isEmpty()) {
+ meterRequestBuilder = DefaultMeterRequest.builder()
+ .forDevice(deviceId)
+ .fromApp(appId)
+ .withUnit(Meter.Unit.KB_PER_SEC)
+ .withBands(bandSet);
+
+ if (bwp.cbs() != 0 || bwp.ebs() != 0) {
+ meterRequestBuilder.burst();
+ }
+
+ // Submit meter request and store
+ meter = meterService.submit(meterRequestBuilder.add());
+ // FIXME: use correct device id
+ log.info("Adding meter...{}", meter.toString());
+
+ meters.add(new ImmutablePair<>(deviceId, meter.id()));
+ }
+ });
+
+ return meters;
+ }
+
+ private FlowRule addMetersToFlowRule(FlowRule flowRule, Set<Pair<DeviceId, MeterId>> deviceMeterIdSet) {
+
+ TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment
+ .builder(flowRule.treatment());
+
+ deviceMeterIdSet.forEach(deviceMeterPair ->
+ tBuilder.meter(deviceMeterPair.getRight()));
+
+ return createFlowRule(flowRule.deviceId(), flowRule.priority(),
+ flowRule.selector(), tBuilder.build(), flowRule.tableId());
+ }
+
+ @Override
+ public void removeBandwidthProfileResources(CarrierEthernetForwardingConstruct fc, CarrierEthernetUni uni) {
+ removeMeters(fc, uni);
+ }
+
+ /**
+ * Removes the meters associated with a specific UNI of an FC.
+ *
+ * @param fc the forwarding construct
+ * @param uni the UNI descriptor
+ * */
+ private void removeMeters(CarrierEthernetForwardingConstruct fc, CarrierEthernetUni uni) {
+
+ if (!fcMeterMap.containsKey(fc.id())) {
+ return;
+ }
+
+ Set<Pair<DeviceId, MeterId>> ids = fcMeterMap.get(fc.id());
+
+ // Rebuild meter request based on existing meter, withdraw the request, and remove it from our internal storage
+ ids.stream()
+ .map(id -> meterService.getMeter(id.getLeft(), id.getRight()))
+ .filter(Objects::nonNull)
+ .forEach(meter -> {
+ MeterRequest.Builder request = DefaultMeterRequest.builder()
+ .fromApp(meter.appId())
+ .forDevice(meter.deviceId())
+ .withUnit(meter.unit())
+ .withBands(meter.bands());
+ if (uni.bwp().cbs() != 0 || uni.bwp().ebs() != 0) {
+ request.burst();
+ }
+ meterService.withdraw(request.remove(), meter.id());
+
+ ids.remove(new ImmutablePair<>(meter.deviceId(), meter.id()));
+ });
+ }
+
+ /**
+ * Removes all flow objectives installed by the application which are associated with a specific FC.
+ *
+ * @param fcId ForwardingConcrtuct object
+ */
+ @Override
+ public void removeAllForwardingResources(EvcConnId fcId) {
+ // Note: A Flow Rule cannot be shared by multiple FCs due to different VLAN or CE-VLAN ID match.
+ List<Pair<DeviceId, Objective>> flowObjectives = flowObjectiveMap.remove(fcId);
+ // NextObjectives will be removed after all other Objectives
+ // TODO: filter also on elements of pair
+ flowObjectives.stream()
+ .filter(Objects::nonNull)
+ .forEach(pair ->
+ flowObjectiveService.apply(pair.getLeft(), pair.getRight().copy().remove()));
+ }
+
+ private FlowRule createFlowRule(DeviceId deviceId, int priority,
+ TrafficSelector selector, TrafficTreatment treatment, int tableId) {
+ return DefaultFlowRule.builder()
+ .fromApp(appId)
+ .forDevice(deviceId)
+ .makePermanent()
+ .withPriority(priority)
+ .withSelector(selector)
+ .withTreatment(treatment)
+ .forTable(tableId)
+ .build();
+ }
+
+ /**
+ * !! Caution !! This method is strictly tied to the expected topology
+ * view of this {@link MetroNetworkVirtualNodeService} implementation.
+ * The UNI is expected to be in the CPE and meters implementation in the EE.
+ * The CPE node shall be connected only
+ * with the EE device (exception are multi path home gateway).
+ *
+ * @param fc forwarding construct
+ * @param uni User to Network Interface
+ * @return the EE device ID
+ */
+ private DeviceId getEEDevice(CarrierEthernetForwardingConstruct fc, CarrierEthernetUni uni)
+ throws IllegalStateException {
+ CarrierEthernetNetworkInterface realUni;
+ Optional<ConnectPoint> optCp =
+ bigSwitchService.connectPointFromVirtPort(uni.cp().port());
+ if (optCp.isPresent()) {
+ realUni = buildLocalNi(optCp.get(), uni);
+ } else {
+ log.info("Virtual ingress interface does not map to a local connect point");
+ throw new IllegalStateException("Virtual UNI interface does not map to a local connect point");
+ }
+ if (eeDeviceMap.get(fc.id()) != null) {
+ return eeDeviceMap.get(fc.id());
+ }
+ // find the (only) egress link of the UNI device
+ Optional<Link> optLink = linkService.getDeviceEgressLinks(realUni.cp().deviceId())
+ .stream().findFirst();
+ if (optLink.isPresent()) {
+
+ // the link destination should be our target EE device
+ DeviceId deviceId = optLink.get().dst().deviceId();
+ log.info("Adding EE device {} in memory...", deviceId.toString());
+ eeDeviceMap.put(fc.id(), deviceId);
+ return deviceId;
+ } else {
+ log.info("No EE device found for meters...uni: {}", realUni.cp().toString());
+ // in this case there is no EE upstream and so no meter will be installed
+ return null;
+ }
+ }
+}
\ No newline at end of file
diff --git a/local/ce-vee/src/main/java/org/opencord/ce/local/vee/package-info.java b/local/ce-vee/src/main/java/org/opencord/ce/local/vee/package-info.java
new file mode 100644
index 0000000..c8ee47d
--- /dev/null
+++ b/local/ce-vee/src/main/java/org/opencord/ce/local/vee/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-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.
+ */
+
+/**
+ * Virtual Ethernet Edge implementation.
+ */
+package org.opencord.ce.local.vee;
\ No newline at end of file
diff --git a/local/common-component/app.xml b/local/common-component/app.xml
new file mode 100644
index 0000000..296464a
--- /dev/null
+++ b/local/common-component/app.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ ~ Copyright 2017-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.
+ -->
+<app name="org.opencord.ce.local.app" origin="ON.Lab" version="${project.version}"
+ category="Utility" url="http://opencord.org" title="Enterprise CORD"
+ featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features"
+ features="${project.artifactId}">
+ <description>${project.description}</description>
+ <artifact>mvn:${project.groupId}/bigswitch/${project.version}</artifact>
+ <artifact>mvn:${project.groupId}/local-channel/${project.version}</artifact>
+</app>
diff --git a/local/common-component/features.xml b/local/common-component/features.xml
new file mode 100644
index 0000000..839d7c3
--- /dev/null
+++ b/local/common-component/features.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+
+<!--
+ ~ Copyright 2017-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.
+ -->
+<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}">
+ <feature name="${project.artifactId}" version="${project.version}"
+ description="${project.description}">
+ <bundle>mvn:${project.groupId}/bigswitch/${project.version}</bundle>
+ <bundle>mvn:${project.groupId}/local-channel/${project.version}</bundle>
+ </feature>
+</features>
\ No newline at end of file
diff --git a/local/common-component/pom.xml b/local/common-component/pom.xml
new file mode 100644
index 0000000..057156a
--- /dev/null
+++ b/local/common-component/pom.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2017-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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.opencord.ce</groupId>
+ <artifactId>local</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>ecord-local-app</artifactId>
+ <packaging>pom</packaging>
+ <version>1.0.0-SNAPSHOT</version>
+
+ <description>Java application bundling the bigswitch abstraction
+ and the HTTP channel component
+ </description>
+
+ <properties>
+ <onos.app.name>org.opencord.ce.local.app</onos.app.name>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.opencord.ce</groupId>
+ <artifactId>bigswitch</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opencord.ce</groupId>
+ <artifactId>local-channel</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+</project>
\ No newline at end of file
diff --git a/local/config-samples/co1-onos-cord-cfg.json b/local/config-samples/co1-onos-cord-cfg.json
new file mode 100644
index 0000000..a908151
--- /dev/null
+++ b/local/config-samples/co1-onos-cord-cfg.json
@@ -0,0 +1,27 @@
+{
+ "apps" : {
+ "org.opencord.ce.local.bigswitch" : {
+ "mefPorts" :
+ [
+ {
+ "mefPortType" : "UNI",
+ "connectPoint" : "netconf:10.0.0.10:830/1"
+ },
+ {
+ "mefPortType" : "INNI",
+ "connectPoint" : "netconf:10.0.0.10:830/0",
+ "interlinkId" : "cm-1"
+ }
+ ]
+ },
+ "org.opencord.ce.local.channel.http" : {
+ "global" : {
+ "publicIp" : "10.128.14.1",
+ "port" : "8182",
+ "username" : "sdn",
+ "password" : "rocks",
+ "topic" : "ecord-domains-topic-one"
+ }
+ }
+ }
+}
diff --git a/local/config-samples/co1-withEE-onos-cord-cfg.json b/local/config-samples/co1-withEE-onos-cord-cfg.json
new file mode 100644
index 0000000..e54cf63
--- /dev/null
+++ b/local/config-samples/co1-withEE-onos-cord-cfg.json
@@ -0,0 +1,41 @@
+{
+ "links": {
+ "netconf:10.0.0.10:830/0-of:0000001e08095936/49" : {
+ "basic" : {
+ "type" : "DIRECT"
+ }
+ },
+ "of:0000001e08095936/49-netconf:10.0.0.10:830/0" : {
+ "basic" : {
+ "type" : "DIRECT"
+ }
+ }
+ },
+ "apps" : {
+ "org.opencord.ce.local.bigswitch" : {
+ "mefPorts" :
+ [
+ {
+ "mefPortType" : "UNI",
+ "connectPoint" : "netconf:10.0.0.10:830/0"
+ },
+ {
+ "mefPortType" : "INNI",
+ "connectPoint" : "of:0000001e08095936/51",
+ "interlinkId" : "cm-1"
+ }
+ ]
+ },
+ "org.opencord.ce.local.channel.http" : {
+ "global" : {
+ "publicIp" : "10.128.14.1",
+ "port" : "8182",
+ "username" : "sdn",
+ "password" : "rocks",
+ "topic" : "ecord-domains-topic-one"
+ }
+ }
+ }
+}
+
+
diff --git a/local/config-samples/co2-onos-cord-cfg.json b/local/config-samples/co2-onos-cord-cfg.json
new file mode 100644
index 0000000..210c7c5
--- /dev/null
+++ b/local/config-samples/co2-onos-cord-cfg.json
@@ -0,0 +1,27 @@
+{
+ "apps" : {
+ "org.opencord.ce.local.bigswitch" : {
+ "mefPorts" :
+ [
+ {
+ "mefPortType" : "UNI",
+ "connectPoint" : "netconf:10.0.0.20:830/1"
+ },
+ {
+ "mefPortType" : "INNI",
+ "connectPoint" : "netconf:10.0.0.20:830/0",
+ "interlinkId" : "cm-1"
+ }
+ ]
+ },
+ "org.opencord.ce.local.channel.http" : {
+ "global" : {
+ "publicIp" : "10.128.14.1",
+ "port" : "8182",
+ "username" : "sdn",
+ "password" : "rocks",
+ "topic" : "ecord-domains-topic-one"
+ }
+ }
+ }
+}
diff --git a/local/config-samples/co2-withEE-onos-cord-cfg.json b/local/config-samples/co2-withEE-onos-cord-cfg.json
new file mode 100644
index 0000000..78b14b5
--- /dev/null
+++ b/local/config-samples/co2-withEE-onos-cord-cfg.json
@@ -0,0 +1,41 @@
+{
+ "links": {
+ "netconf:10.0.0.20:830/0-of:0000001e08095936/50" : {
+ "basic" : {
+ "type" : "DIRECT"
+ }
+ },
+ "of:0000001e08095936/50-netconf:10.0.0.20:830/0" : {
+ "basic" : {
+ "type" : "DIRECT"
+ }
+ }
+ },
+ "apps" : {
+ "org.opencord.ce.local.bigswitch" : {
+ "mefPorts" :
+ [
+ {
+ "mefPortType" : "UNI",
+ "connectPoint" : "netconf:10.0.0.20:830/0"
+ },
+ {
+ "mefPortType" : "INNI",
+ "connectPoint" : "of:0000001e08095936/49",
+ "interlinkId" : "cm-1"
+ }
+ ]
+ },
+ "org.opencord.ce.local.channel.http" : {
+ "global" : {
+ "publicIp" : "10.128.14.1",
+ "port" : "8182",
+ "username" : "sdn",
+ "password" : "rocks",
+ "topic" : "ecord-domains-topic-one"
+ }
+ }
+ }
+}
+
+
diff --git a/local/config-samples/onos-fabric-cfg.json b/local/config-samples/onos-fabric-cfg.json
new file mode 100644
index 0000000..a9a6f6f
--- /dev/null
+++ b/local/config-samples/onos-fabric-cfg.json
@@ -0,0 +1,38 @@
+{
+ "apps" : {
+ "org.opencord.ce.local.fabric" : {
+ "segmentrouting_ctl": {
+ "publicIp": "127.0.0.1",
+ "port": "8181",
+ "username": "sdn",
+ "password": "rocks",
+ "deviceId": "of:0000001e08095936"
+ }
+ },
+ "org.opencord.ce.local.bigswitch" : {
+ "mefPorts" :
+ [
+ {
+ "mefPortType" : "INNI",
+ "connectPoint" : "of:0000001e08095936/1",
+ "interlinkId" : "EE-2-fabric"
+ },
+ {
+ "mefPortType" : "ENNI",
+ "connectPoint" : "of:0000001e08095936/49",
+ "interlinkId" : "fabric-upstream"
+ }
+ ]
+ },
+ "org.opencord.ce.local.channel.http" : {
+ "global" : {
+ "publicIp" : "10.128.14.1",
+ "port" : "8182",
+ "username" : "sdn",
+ "password" : "rocks",
+ "topic" : "ecord-domains-topic-one"
+ }
+ }
+
+ }
+}
diff --git a/local/http-channel/pom.xml b/local/http-channel/pom.xml
new file mode 100644
index 0000000..90e4c64
--- /dev/null
+++ b/local/http-channel/pom.xml
@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2017-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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.opencord.ce</groupId>
+ <artifactId>local</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>local-channel</artifactId>
+ <packaging>bundle</packaging>
+ <version>1.0.0-SNAPSHOT</version>
+
+ <description>Http communication channel between hierarchic ONOS controllers</description>
+
+ <properties>
+ <onos.app.name>org.opencord.ce.local.channel.http</onos.app.name>
+ <web.context>/ecord</web.context>
+ <onos.app.title>E-CORD CE App</onos.app.title>
+ <onos.app.url>http://opencord.org</onos.app.url>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.opencord.ce</groupId>
+ <artifactId>bigswitch</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <_wab>src/main/webapp/</_wab>
+ <Bundle-SymbolicName>
+ ${project.groupId}.${project.artifactId}
+ </Bundle-SymbolicName>
+ <Import-Package>
+ *,org.glassfish.jersey.servlet
+ </Import-Package>
+ <Web-ContextPath>${web.context}</Web-ContextPath>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+ <repositories>
+ <repository>
+ <id>snapshots</id>
+ <url>https://oss.sonatype.org/content/repositories/snapshots</url>
+ <releases><enabled>false</enabled></releases>
+ </repository>
+ </repositories>
+
+ <pluginRepositories>
+ <pluginRepository>
+ <id>snapshots</id>
+ <url>https://oss.sonatype.org/content/repositories/snapshots</url>
+ <releases><enabled>false</enabled></releases>
+ </pluginRepository>
+ </pluginRepositories>
+</project>
\ No newline at end of file
diff --git a/local/http-channel/src/main/java/org/opencord/ce/local/channel/client/ConnectionConfig.java b/local/http-channel/src/main/java/org/opencord/ce/local/channel/client/ConnectionConfig.java
new file mode 100644
index 0000000..2113862
--- /dev/null
+++ b/local/http-channel/src/main/java/org/opencord/ce/local/channel/client/ConnectionConfig.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2017-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.opencord.ce.local.channel.client;
+
+import com.google.common.collect.Sets;
+import org.onlab.packet.IpAddress;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.net.config.Config;
+import org.onosproject.net.domain.DomainId;
+import org.opencord.ce.api.models.DomainEndPoint;
+
+import java.util.Set;
+
+/**
+ * Configuration class for this bundle.
+ * Currently this configuration is simply the connection endpoint of the global ONOS.
+ *
+ * Look at config-samples/ecord-local-config.json for a sample configuration
+ */
+public class ConnectionConfig extends Config<ApplicationId> {
+
+ private static final String PORT = "port";
+ private static final String PUBLIC_IP = "publicIp";
+ private static final String USERNAME = "username";
+ private static final String PASSWD = "password";
+ private static final String TOPIC = "topic";
+
+ public DomainEndPoint global() {
+ Set<IpAddress> ipAddresses = Sets.newHashSet();
+ IpAddress publicIp = IpAddress.valueOf(object.path(PUBLIC_IP).asText());
+ int port = object.path(PORT).asInt();
+
+ String username = object.path(USERNAME).asText();
+ String password = object.path(PASSWD).asText();
+
+ String topic = object.path(TOPIC).asText();
+
+ return new DomainEndPoint(DomainId.domainId("global"), publicIp, port,
+ username, password, topic);
+ }
+}
diff --git a/local/http-channel/src/main/java/org/opencord/ce/local/channel/client/DomainMasterIpDiscoveryTask.java b/local/http-channel/src/main/java/org/opencord/ce/local/channel/client/DomainMasterIpDiscoveryTask.java
new file mode 100644
index 0000000..e8513c9
--- /dev/null
+++ b/local/http-channel/src/main/java/org/opencord/ce/local/channel/client/DomainMasterIpDiscoveryTask.java
@@ -0,0 +1,125 @@
+/*
+ * Copyright 2017-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.opencord.ce.local.channel.client;
+
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.jboss.netty.util.Timeout;
+import org.jboss.netty.util.TimerTask;
+import org.onlab.packet.IpAddress;
+import org.onlab.util.Timer;
+import org.opencord.ce.api.models.DomainEndPoint;
+import org.slf4j.Logger;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static org.opencord.ce.api.services.channel.Symbols.BASE_URL;
+import static org.opencord.ce.api.services.channel.Symbols.COLON;
+import static org.opencord.ce.api.services.channel.Symbols.DOUBLESLASH;
+import static org.opencord.ce.api.services.channel.Symbols.HTTP;
+import static org.opencord.ce.api.services.channel.Symbols.MASTER;
+import static org.opencord.ce.api.services.channel.Symbols.MASTER_IP;
+import static org.opencord.ce.api.services.channel.Symbols.OK;
+import static org.opencord.ce.api.services.channel.Symbols.RESULT;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Executed periodically to find the leader node of a domain.
+ * Stops when the ip is found
+ */
+public class DomainMasterIpDiscoveryTask implements TimerTask {
+
+ private final Logger log = getLogger(getClass());
+
+ private Timeout timeout;
+ private volatile boolean isStopped;
+ private DomainEndPoint endPoint;
+ private Client client;
+ private String localSiteId;
+
+ private ObjectMapper mapper;
+
+ public DomainMasterIpDiscoveryTask(DomainEndPoint endPoint, Client client,
+ ObjectMapper mapper, String localSiteId) {
+ this.endPoint = endPoint;
+ this.client = client;
+ this.mapper = mapper;
+ this.localSiteId = localSiteId;
+
+ isStopped = true;
+ start();
+
+ }
+
+ public synchronized void stop() {
+ if (!isStopped) {
+ isStopped = true;
+ timeout.cancel();
+ } else {
+ log.warn("IpDiscovery stopped multiple times?");
+ }
+ }
+
+ public synchronized void start() {
+ if (isStopped) {
+ isStopped = false;
+ timeout = Timer.getTimer().newTimeout(this, 0, SECONDS);
+ } else {
+ log.warn("IpDiscovery started multiple times?");
+ }
+ }
+
+ public synchronized boolean isStopped() {
+ return isStopped || timeout.isCancelled();
+ }
+
+ @Override
+ public void run(Timeout t) {
+ if (isStopped()) {
+ return;
+ }
+ String url = HTTP + COLON + DOUBLESLASH + endPoint.publicIp() + COLON +
+ endPoint.port() + BASE_URL + "/global" + MASTER + "/" + localSiteId;
+ log.info("GET: " + url);
+ WebTarget wt = client.target(url);
+ Response response = wt.request(MediaType.APPLICATION_JSON)
+ .get();
+ log.info("DEBUG response: " + response.toString());
+ if (response.getStatus() == Response.Status.OK.getStatusCode()) {
+ String stringBody = response.readEntity(String.class);
+ try {
+ ObjectNode responseBody = (ObjectNode) mapper.readTree(stringBody);
+ if (responseBody.path(RESULT).asText().equals(OK)) {
+ IpAddress masterIpAdress = IpAddress.valueOf(responseBody.path(MASTER_IP).asText());
+ this.stop();
+ return;
+ }
+ } catch (IOException ex) {
+ log.info("getLocalMasterIp() IOException, try next endpoint ip");
+ }
+ }
+ if (!isStopped()) {
+ timeout = Timer.getTimer().newTimeout(this, 3, SECONDS);
+ }
+ }
+}
diff --git a/local/http-channel/src/main/java/org/opencord/ce/local/channel/client/HttpClientComponent.java b/local/http-channel/src/main/java/org/opencord/ce/local/channel/client/HttpClientComponent.java
new file mode 100644
index 0000000..a29299b
--- /dev/null
+++ b/local/http-channel/src/main/java/org/opencord/ce/local/channel/client/HttpClientComponent.java
@@ -0,0 +1,177 @@
+/*
+ * Copyright 2017-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.opencord.ce.local.channel.client;
+
+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.onosproject.cluster.ClusterService;
+import org.onosproject.cluster.LeadershipService;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.onosproject.net.config.ConfigFactory;
+import org.onosproject.net.config.NetworkConfigEvent;
+import org.onosproject.net.config.NetworkConfigListener;
+import org.onosproject.net.config.NetworkConfigRegistry;
+import org.onosproject.net.config.NetworkConfigService;
+import org.onosproject.net.config.basics.SubjectFactories;
+import org.onosproject.net.device.PortDescription;
+import org.opencord.ce.api.models.DomainEndPoint;
+import org.opencord.ce.local.bigswitch.BigSwitchEvent;
+import org.opencord.ce.local.bigswitch.BigSwitchListener;
+import org.opencord.ce.local.bigswitch.BigSwitchService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+/**
+ * Component that reacts to the BigSwitch events by notifying the global ONOS orchestrator.
+ */
+// TODO: better name
+@Component(immediate = true)
+public class HttpClientComponent {
+ private static final String APP_NAME = "org.opencord.ce.local.channel.http";
+
+ // temporary
+ private static final String TOPIC_ONE = "ecord-domains-topic-one";
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+ private ApplicationId appId;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected ClusterService clusterService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected LeadershipService leadershipService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected NetworkConfigRegistry configRegistry;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected NetworkConfigService configService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected CoreService coreService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected BigSwitchService bigSwitchService;
+
+ private static DomainEndPoint globalOnos;
+
+ private final ExecutorService eventExecutor =
+ Executors.newSingleThreadExecutor();
+
+ private final ConfigFactory<ApplicationId, ConnectionConfig> configFactory =
+ new ConfigFactory<ApplicationId, ConnectionConfig>(SubjectFactories.APP_SUBJECT_FACTORY,
+ ConnectionConfig.class, "global") {
+ @Override
+ public ConnectionConfig createConfig() {
+ return new ConnectionConfig();
+ }
+ };
+
+ private final NetworkConfigListener configListener = new InternalConfigListener();
+ private final BigSwitchListener bigSwitchListener = new InternalBigSwitchListener();
+
+ @Activate
+ public void activate() {
+ log.info("Started");
+
+ appId = coreService.registerApplication(APP_NAME);
+ leadershipService.runForLeadership(TOPIC_ONE);
+ configRegistry.registerConfigFactory(configFactory);
+ configService.addListener(configListener);
+ bigSwitchService.addListener(bigSwitchListener);
+ HttpClientInstance.INSTANCE.configure(clusterService, leadershipService);
+ }
+
+ @Deactivate
+ public void deactivate() {
+ log.info("Stopped");
+ leadershipService.withdraw(TOPIC_ONE);
+ bigSwitchService.removeListener(bigSwitchListener);
+ configService.removeListener(configListener);
+ configRegistry.unregisterConfigFactory(configFactory);
+ if (globalOnos != null) {
+ leadershipService.withdraw(globalOnos.topic());
+ }
+ }
+
+ private void readConfig() {
+ globalOnos = configRegistry.getConfig(appId, ConnectionConfig.class)
+ .global();
+ if (globalOnos == null) {
+ log.error("Configuration failure");
+ return;
+ }
+ leadershipService.runForLeadership(globalOnos.topic());
+ HttpClientInstance.INSTANCE.setGlobalOnos(globalOnos);
+ }
+
+ private class InternalBigSwitchListener implements BigSwitchListener {
+
+ @Override
+ public void event(BigSwitchEvent event) {
+ log.info(event.toString());
+ switch (event.type()) {
+ case DEVICE_CREATED:
+ log.info("DEBUG: DEV_CREATED event");
+ HttpClientInstance.INSTANCE.notifyBigSwitch(bigSwitchService.domainId());
+ case PORT_ADDED:
+ case PORT_UPDATED:
+ case PORT_REMOVED:
+ // the subject is port last updated / added port
+ // but we are not interested in it now
+ List<PortDescription> ports = event.allPorts();
+ HttpClientInstance.INSTANCE.notifyBigSwitchPorts(bigSwitchService.domainId(), ports);
+ break;
+ case DEVICE_REMOVED:
+ // TODO
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ private class InternalConfigListener implements NetworkConfigListener {
+
+ @Override
+ public void event(NetworkConfigEvent event) {
+ if (!event.configClass().equals(ConnectionConfig.class)) {
+ return;
+ }
+ switch (event.type()) {
+ case CONFIG_ADDED:
+ log.info("Network configuration added");
+ eventExecutor.execute(HttpClientComponent.this::readConfig);
+ break;
+ case CONFIG_UPDATED:
+ log.info("Network configuration updated");
+ eventExecutor.execute(HttpClientComponent.this::readConfig);
+ break;
+ default:
+ break;
+ }
+ }
+ }
+}
diff --git a/local/http-channel/src/main/java/org/opencord/ce/local/channel/client/HttpClientInstance.java b/local/http-channel/src/main/java/org/opencord/ce/local/channel/client/HttpClientInstance.java
new file mode 100644
index 0000000..132e648
--- /dev/null
+++ b/local/http-channel/src/main/java/org/opencord/ce/local/channel/client/HttpClientInstance.java
@@ -0,0 +1,227 @@
+/*
+ * Copyright 2017-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.opencord.ce.local.channel.client;
+
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onlab.packet.ChassisId;
+import org.onosproject.cluster.ClusterService;
+import org.onosproject.cluster.LeadershipService;
+import org.onosproject.codec.JsonCodec;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.DefaultDevice;
+import org.onosproject.net.DefaultPort;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.Port;
+import org.onosproject.net.device.PortDescription;
+import org.onosproject.net.domain.DomainId;
+import org.onosproject.net.provider.ProviderId;
+import org.onosproject.rest.AbstractWebResource;
+import org.opencord.ce.api.models.DomainEndPoint;
+import org.opencord.ce.api.services.channel.RequestCallback;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+
+import static java.util.concurrent.Executors.newSingleThreadExecutor;
+import static org.opencord.ce.api.services.channel.Symbols.BASE_URL;
+import static org.opencord.ce.api.services.channel.Symbols.COLON;
+import static org.opencord.ce.api.services.channel.Symbols.DELETE;
+import static org.opencord.ce.api.services.channel.Symbols.DOUBLESLASH;
+import static org.opencord.ce.api.services.channel.Symbols.GET;
+import static org.opencord.ce.api.services.channel.Symbols.HTTP;
+import static org.opencord.ce.api.services.channel.Symbols.POST;
+
+/**
+ * HTTP client instance used to communicate
+ * to the global ONOS events related to the big switch topology abstraction.
+ */
+public enum HttpClientInstance {
+ INSTANCE;
+ private final Logger log =
+ LoggerFactory.getLogger(HttpClientInstance.class);
+ private static final Object MONITOR = new Object();
+
+ private static final int STATUS_OK = Response.Status.OK.getStatusCode();
+ private static final int STATUS_REQ_UNPROCESSABLE = Response.Status.NOT_ACCEPTABLE.getStatusCode();
+
+ private final AbstractWebResource codecContext = new AbstractWebResource();
+ private final Client client = ClientBuilder.newClient();
+
+ private ClusterService clusterService;
+ private LeadershipService leadershipService;
+ private DomainEndPoint globalOnos;
+
+ private final ExecutorService networkExecutor =
+ newSingleThreadExecutor();
+
+ public void configure(ClusterService clusterService, LeadershipService leadershipService) {
+ this.clusterService = clusterService;
+ this.leadershipService = leadershipService;
+ }
+
+ protected void setGlobalOnos(DomainEndPoint globalOnos) {
+ synchronized (MONITOR) {
+ this.globalOnos = globalOnos;
+ }
+ }
+
+ private boolean isLeader(String topic) {
+ return leadershipService.getLeader(topic).id()
+ .equals(clusterService.getLocalNode().id().id());
+ }
+
+ private boolean checkReply(Response response) {
+ if (response != null) {
+ return checkStatusCode(response.getStatus());
+ }
+ log.error("Null reply from end point");
+ return false;
+ }
+
+ private boolean checkStatusCode(int statusCode) {
+ if (statusCode == STATUS_OK) {
+ return true;
+ } else {
+ log.error("Failed request, HTTP error code : "
+ + statusCode);
+ return false;
+ }
+ }
+
+ public void notifyBigSwitch(DomainId siteId) {
+ String deviceId = "domain:" + siteId.id();
+ String resource = "/" + siteId + "/" + deviceId;
+ ObjectNode body = codecContext.mapper().createObjectNode();
+ // body is empty for now
+ networkExecutor.execute(new NetworkTask(POST, resource, body.toString(), new RequestCallback() {
+ @Override
+ public void onSuccess(Response response) {
+
+ }
+
+ @Override
+ public void onError(Response response) {
+
+ }
+ }));
+ }
+
+ public void notifyBigSwitchPorts(DomainId siteId, List<PortDescription> ports) {
+ JsonCodec<Port> portCodec = codecContext.codec(Port.class);
+ ArrayNode body = codecContext.mapper().createArrayNode();
+ DeviceId deviceId = DeviceId.deviceId("domain:" + siteId.id());
+ ports.forEach(portDescription ->
+ body.add(portCodec.encode(new DefaultPort(new DummyDevice(deviceId), portDescription.portNumber(),
+ portDescription.isEnabled(), portDescription.type(),
+ portDescription.portSpeed(), portDescription.annotations()), codecContext)));
+ String resource = "/" + siteId + "/" + deviceId + "/ports";
+ networkExecutor.execute(new NetworkTask(POST, resource, body.toString(), new RequestCallback() {
+ @Override
+ public void onSuccess(Response response) {
+
+ }
+
+ @Override
+ public void onError(Response response) {
+
+ }
+ }));
+
+ }
+
+ private class NetworkTask implements Runnable {
+ private String method;
+ private String resource;
+ private String body;
+ private RequestCallback callback;
+
+ NetworkTask(String method, String resource, String body,
+ RequestCallback callback) {
+ this.method = method;
+ this.resource = resource;
+ this.body = body;
+ this.callback = callback;
+ }
+ @Override
+ public void run() {
+ synchronized (MONITOR) {
+ while (globalOnos == null) {
+ try {
+ log.info("wait() global ONOS endpoint");
+ MONITOR.wait();
+ } catch (InterruptedException ie) {
+ log.info("Interrupted exception: " + ie.getMessage());
+ }
+ }
+ }
+ if (!isLeader(globalOnos.topic())) {
+ return;
+ }
+ String url = HTTP + COLON + DOUBLESLASH + globalOnos.publicIp() + COLON +
+ globalOnos.port() + BASE_URL + "/global/topology" + resource;
+
+ log.info("Sending data via http: url: {}\n body: {}", url, body);
+
+ WebTarget webTarget = client.target(url);
+ Response response;
+ switch (method) {
+ case POST:
+ response = webTarget.request(MediaType.APPLICATION_JSON)
+ .post(Entity.entity(body, MediaType.APPLICATION_JSON));
+ break;
+ case DELETE:
+ response = webTarget.request(MediaType.APPLICATION_JSON).delete();
+ break;
+ case GET:
+ default:
+ response = webTarget.request(MediaType.APPLICATION_JSON).get();
+ break;
+ }
+
+ if (!checkReply(response)) {
+ callback.onError(response);
+ } else {
+ callback.onSuccess(response);
+ }
+ }
+ }
+
+ /**
+ * Dummy Device which only holds DeviceId.
+ */
+ private static final class DummyDevice extends DefaultDevice {
+ /**
+ * Constructs Dummy Device which only holds DeviceId.
+ *
+ * @param did device Id
+ */
+ public DummyDevice(DeviceId did) {
+ super(new ProviderId(did.uri().getScheme(), "PortCodec"), did,
+ Type.SWITCH, "dummy", "0", "0", "0", new ChassisId(),
+ DefaultAnnotations.EMPTY);
+ }
+ }
+}
diff --git a/local/http-channel/src/main/java/org/opencord/ce/local/channel/client/TestTopology.java b/local/http-channel/src/main/java/org/opencord/ce/local/channel/client/TestTopology.java
new file mode 100644
index 0000000..23f1337
--- /dev/null
+++ b/local/http-channel/src/main/java/org/opencord/ce/local/channel/client/TestTopology.java
@@ -0,0 +1,211 @@
+/*
+ * Copyright 2017-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.opencord.ce.local.channel.client;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.onlab.packet.ChassisId;
+import org.onosproject.core.CoreService;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.Device;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.Link;
+import org.onosproject.net.MastershipRole;
+import org.onosproject.net.Port;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.SparseAnnotations;
+import org.onosproject.net.device.DefaultDeviceDescription;
+import org.onosproject.net.device.DefaultPortDescription;
+import org.onosproject.net.device.DeviceDescription;
+import org.onosproject.net.device.DeviceProvider;
+import org.onosproject.net.device.DeviceProviderRegistry;
+import org.onosproject.net.device.DeviceProviderService;
+import org.onosproject.net.device.PortDescription;
+import org.onosproject.net.link.DefaultLinkDescription;
+import org.onosproject.net.link.LinkDescription;
+import org.onosproject.net.link.LinkProvider;
+import org.onosproject.net.link.LinkProviderRegistry;
+import org.onosproject.net.link.LinkProviderService;
+import org.onosproject.net.provider.ProviderId;
+import org.slf4j.Logger;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+import java.util.concurrent.ThreadLocalRandom;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Inject fake topology elements.
+ */
+//@Component(immediate = true)
+public class TestTopology implements DeviceProvider,
+ LinkProvider {
+ public static final String PROVIDER_NAME = "org.opencord.ce.local.test";
+ public static final ProviderId PROVIDER_ID = new ProviderId("test", PROVIDER_NAME);
+ private static final String UNKNOWN = "unknown";
+
+ private final Logger log = getLogger(getClass());
+ public static final String TEST_DEV_PREFIX = "test:0000";
+ public static final int NUM = 1;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected CoreService coreService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected DeviceProviderRegistry deviceProviderRegistry;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected LinkProviderRegistry linkProviderRegistry;
+
+ protected DeviceProviderService deviceProviderService;
+ protected LinkProviderService linkProviderService;
+
+ @Override
+ public ProviderId id() {
+ return PROVIDER_ID;
+ }
+
+ @Activate
+ public void activate() {
+ coreService.registerApplication(PROVIDER_NAME);
+ deviceProviderService = deviceProviderRegistry.register(this);
+ linkProviderService = linkProviderRegistry.register(this);
+
+ new Thread(this::buildFakeNetwork).start();
+
+ log.info("Started");
+ }
+
+ @Deactivate
+ public void deactivate() {
+ deviceProviderRegistry.unregister(this);
+ linkProviderRegistry.unregister(this);
+ log.info("Stopped");
+ }
+
+ @Override
+ public void triggerProbe(DeviceId deviceId){
+
+ }
+
+ @Override
+ public void roleChanged(DeviceId deviceId, MastershipRole newRole) {
+
+ }
+
+ @Override
+ public boolean isReachable(DeviceId deviceId) {
+ return true;
+ }
+
+ @Override
+ public void changePortState(DeviceId deviceId, PortNumber portNumber,
+ boolean enable) {
+
+ }
+
+ private void buildFakeNetwork() {
+ ChassisId chassisId = new ChassisId();
+ SparseAnnotations annotations = DefaultAnnotations.builder()
+ .set("no-lldp", "any")
+ .set("test", "test")
+ .build();
+ int i;
+ int j;
+ for (i = 1; i <= NUM; i++) {
+ DeviceId deviceId = DeviceId.deviceId(TEST_DEV_PREFIX + i);
+ DeviceDescription deviceDescription = new DefaultDeviceDescription(
+ deviceId.uri(),
+ Device.Type.SWITCH,
+ UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN,
+ chassisId, annotations);
+ deviceProviderService.deviceConnected(deviceId, deviceDescription);
+ List<PortDescription> ports = new ArrayList<>();
+ for (j = 1; j <= NUM; j++) {
+ ports.add(new DefaultPortDescription(PortNumber.portNumber(j),
+ true, Port.Type.FIBER, 10000,
+ annotations));
+
+ }
+ deviceProviderService.updatePorts(deviceId, ports);
+
+ String macString = randomMCAddress();
+ log.info("MacString: {}", macString);
+/*
+ HostDescription hostDescription = new DefaultHostDescription(MacAddress.valueOf(macString),
+ VlanId.NONE,
+ new HostLocation(deviceId, PortNumber.portNumber(1), 0),
+ annotations);
+ hostProviderService.hostDetected(hostId, hostDescription, true);
+ */
+ }
+
+ long seed = (long) ThreadLocalRandom.current().nextDouble();
+ Random rand = new Random(seed);
+ for (i = 1; i <= NUM; i++) {
+ for (j = i + 1; j <= NUM; j++) {
+
+
+ if (rand.nextDouble() > 0.5) {
+ continue;
+ }
+
+ LinkDescription linkDescription = new DefaultLinkDescription(
+ ConnectPoint.deviceConnectPoint(TEST_DEV_PREFIX + i + "/" + j),
+ ConnectPoint.deviceConnectPoint(TEST_DEV_PREFIX + j + "/" + (i + 1)),
+ Link.Type.DIRECT,
+ true,
+ annotations
+ );
+ LinkDescription linkDescription1 = new DefaultLinkDescription(
+ ConnectPoint.deviceConnectPoint(TEST_DEV_PREFIX + j + "/" + (i + 1)),
+ ConnectPoint.deviceConnectPoint(TEST_DEV_PREFIX + i + "/" + j),
+ Link.Type.DIRECT,
+ true,
+ annotations
+ );
+ linkProviderService.linkDetected(linkDescription);
+ linkProviderService.linkDetected(linkDescription1);
+ }
+ }
+ }
+ private String randomMCAddress() {
+ Random rand = new Random();
+ byte[] macAddr = new byte[6];
+ rand.nextBytes(macAddr);
+
+ macAddr[0] = (byte) (macAddr[0] & (byte) 254); //zeroing last 2
+ // bytes to make it unicast and locally adminstrated
+ StringBuilder sb = new StringBuilder(18);
+ for (byte b : macAddr) {
+
+ if (sb.length() > 0) {
+ sb.append(":");
+ }
+ sb.append(String.format("%02x", b));
+ }
+ return sb.toString();
+ }
+
+
+
+}
diff --git a/local/http-channel/src/main/java/org/opencord/ce/local/channel/client/package-info.java b/local/http-channel/src/main/java/org/opencord/ce/local/channel/client/package-info.java
new file mode 100644
index 0000000..f961747
--- /dev/null
+++ b/local/http-channel/src/main/java/org/opencord/ce/local/channel/client/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-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.
+ */
+
+/**
+ * Implementation of the client-side communication channel APIs.
+ */
+package org.opencord.ce.local.channel.client;
\ No newline at end of file
diff --git a/local/http-channel/src/main/java/org/opencord/ce/local/channel/server/EcordLocalRestApp.java b/local/http-channel/src/main/java/org/opencord/ce/local/channel/server/EcordLocalRestApp.java
new file mode 100644
index 0000000..51b8b32
--- /dev/null
+++ b/local/http-channel/src/main/java/org/opencord/ce/local/channel/server/EcordLocalRestApp.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2017-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.opencord.ce.local.channel.server;
+
+import org.onlab.rest.AbstractWebApplication;
+
+import java.util.Set;
+
+
+/**
+ * Loader class for web resource APIs.
+ */
+public class EcordLocalRestApp extends AbstractWebApplication {
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ return getClasses(MetroNetworkResource.class);
+ }
+}
diff --git a/local/http-channel/src/main/java/org/opencord/ce/local/channel/server/MetroNetworkResource.java b/local/http-channel/src/main/java/org/opencord/ce/local/channel/server/MetroNetworkResource.java
new file mode 100644
index 0000000..acd04cd
--- /dev/null
+++ b/local/http-channel/src/main/java/org/opencord/ce/local/channel/server/MetroNetworkResource.java
@@ -0,0 +1,176 @@
+/*
+ * Copyright 2017-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.opencord.ce.local.channel.server;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onosproject.codec.JsonCodec;
+import org.onosproject.rest.AbstractWebResource;
+import org.opencord.ce.api.models.CarrierEthernetForwardingConstruct;
+import org.opencord.ce.api.models.CarrierEthernetNetworkInterface;
+import org.opencord.ce.api.models.CarrierEthernetUni;
+import org.opencord.ce.api.models.EvcConnId;
+import org.opencord.ce.api.services.MetroNetworkVirtualNodeService;
+import org.slf4j.Logger;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Web resource for {@link MetroNetworkVirtualNodeService}
+ * APIs.
+ */
+@Path("carrierethernet")
+public class MetroNetworkResource extends AbstractWebResource {
+ private final Logger log = getLogger(getClass());
+ private static final String FC = "fc";
+ private static final String SRC_NI = "srcNi";
+ private static final String DST_NI_LIST = "dstNiList";
+ private static final String UNI = "uni";
+
+ private JsonCodec<CarrierEthernetForwardingConstruct> fcCodec =
+ codec(CarrierEthernetForwardingConstruct.class);
+ private JsonCodec<CarrierEthernetNetworkInterface> niCodec =
+ codec(CarrierEthernetNetworkInterface.class);
+
+ @Path("ForwardingConstruct")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @POST
+ public Response setNodeForwarding(InputStream stream) {
+ try {
+ JsonNode responseBody = mapper().readTree(stream);
+ log.info(responseBody.toString());
+ MetroNetworkVirtualNodeService localNodeService =
+ get(MetroNetworkVirtualNodeService.class);
+
+ CarrierEthernetForwardingConstruct fc =
+ fcCodec.decode((ObjectNode) responseBody.path(FC), this);
+ CarrierEthernetNetworkInterface srcNi =
+ niCodec.decode((ObjectNode) responseBody.path(SRC_NI), this);
+ Set<CarrierEthernetNetworkInterface> dstNiSet = new HashSet<>();
+ responseBody.path(DST_NI_LIST).forEach(jsonDstNi ->
+ dstNiSet.add(niCodec.decode((ObjectNode) jsonDstNi, this)));
+
+ localNodeService.setNodeForwarding(fc, srcNi, dstNiSet);
+ return Response.status(200).build();
+ } catch (IOException io) {
+ log.info("Json parse error");
+ return Response.status(Response.Status.NOT_ACCEPTABLE).build();
+ }
+ }
+
+ @Path("createBwp")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @POST
+ public Response createBandwidthProfileResources(InputStream stream) {
+ try {
+ MetroNetworkVirtualNodeService localNodeService =
+ get(MetroNetworkVirtualNodeService.class);
+
+ JsonNode responseBody = mapper().readTree(stream);
+ log.info(responseBody.toString());
+
+ CarrierEthernetForwardingConstruct fc =
+ fcCodec.decode((ObjectNode) responseBody.path(FC), this);
+ CarrierEthernetUni uni = (CarrierEthernetUni)
+ niCodec.decode((ObjectNode) responseBody.path(UNI), this);
+ localNodeService.createBandwidthProfileResources(fc, uni);
+ return Response.status(200).build();
+ } catch (IOException io) {
+ log.info("Json parse error");
+ return Response.status(Response.Status.NOT_ACCEPTABLE).build();
+ }
+ }
+
+ @Path("applyBwp")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @POST
+ public Response applyBandwidthProfileResources(InputStream stream) {
+ try {
+ MetroNetworkVirtualNodeService localNodeService =
+ get(MetroNetworkVirtualNodeService.class);
+
+ JsonNode responseBody = mapper().readTree(stream);
+ log.info(responseBody.toString());
+
+ CarrierEthernetForwardingConstruct fc =
+ fcCodec.decode((ObjectNode) responseBody.path(FC), this);
+ CarrierEthernetUni uni = (CarrierEthernetUni)
+ niCodec.decode((ObjectNode) responseBody.path(UNI), this);
+
+ localNodeService.applyBandwidthProfileResources(fc, uni);
+ return Response.status(200).build();
+ } catch (IOException io) {
+ log.info("Json parse error");
+ return Response.status(Response.Status.NOT_ACCEPTABLE).build();
+ }
+ }
+
+ @Path("deleteBwp")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @POST
+ public Response removeBandwidthProfileResources(InputStream stream) {
+ try {
+ MetroNetworkVirtualNodeService localNodeService =
+ get(MetroNetworkVirtualNodeService.class);
+
+ JsonNode responseBody = mapper().readTree(stream);
+ log.info(responseBody.toString());
+
+ CarrierEthernetForwardingConstruct fc =
+ fcCodec.decode((ObjectNode) responseBody.path(FC), this);
+
+ CarrierEthernetUni uni = (CarrierEthernetUni)
+ niCodec.decode((ObjectNode) responseBody.path(UNI), this);
+
+ localNodeService.applyBandwidthProfileResources(fc, uni);
+ return Response.status(200).build();
+ } catch (IOException io) {
+ log.info("Json parse error");
+ return Response.status(Response.Status.NOT_ACCEPTABLE).build();
+ }
+ }
+
+ @Path("deleteFcResources/{fcId}")
+ @Produces(MediaType.APPLICATION_JSON)
+ @GET
+ public Response removeAllForwardingResources(@PathParam("{fcId}") String fcId) {
+ EvcConnId evcId = EvcConnId.of(fcId);
+ MetroNetworkVirtualNodeService localNodeService =
+ get(MetroNetworkVirtualNodeService.class);
+
+ localNodeService.removeAllForwardingResources(evcId);
+ return Response.status(200).build();
+ }
+}
diff --git a/local/http-channel/src/main/java/org/opencord/ce/local/channel/server/package-info.java b/local/http-channel/src/main/java/org/opencord/ce/local/channel/server/package-info.java
new file mode 100644
index 0000000..d2886b7
--- /dev/null
+++ b/local/http-channel/src/main/java/org/opencord/ce/local/channel/server/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-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.
+ */
+
+/**
+ * Implementation of the server-side communication channel APIs.
+ */
+package org.opencord.ce.local.channel.server;
\ No newline at end of file
diff --git a/local/http-channel/src/main/webapp/WEB-INF/web.xml b/local/http-channel/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..06ebfcd
--- /dev/null
+++ b/local/http-channel/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2017-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.
+ -->
+<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+ id="ONOS" version="2.5">
+ <display-name>ICONA REST API v1.0</display-name>
+
+ <servlet>
+ <servlet-name>JAX-RS Service</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.opencord.ce.local.channel.server.EcordLocalRestApp</param-value>
+ </init-param>
+ <load-on-startup>10</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>JAX-RS Service</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/local/pom.xml b/local/pom.xml
new file mode 100644
index 0000000..ed76a1c
--- /dev/null
+++ b/local/pom.xml
@@ -0,0 +1,106 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2017-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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.opencord</groupId>
+ <artifactId>ce</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.opencord.ce</groupId>
+ <artifactId>local</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <description>Local components of the CORD Carrier Ethernet service</description>
+
+ <properties>
+ <onos.version>1.10.6</onos.version>
+ <onos.app.title>E-CORD Carrier Ethernet local site component</onos.app.title>
+ <onos.app.url>http://opencord.org</onos.app.url>
+ </properties>
+
+ <modules>
+ <module>bigswitch</module>
+ <module>http-channel</module>
+ <module>ce-transport</module>
+ <module>ce-vee</module>
+ <module>ce-fabric</module>
+ <module>common-component</module>
+ </modules>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.opencord.ce</groupId>
+ <artifactId>ce-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onlab-junit</artifactId>
+ <version>${onos.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+ <repositories>
+ <repository>
+ <id>snapshots</id>
+ <url>https://oss.sonatype.org/content/repositories/snapshots</url>
+ <releases><enabled>false</enabled></releases>
+ </repository>
+ </repositories>
+
+ <pluginRepositories>
+ <pluginRepository>
+ <id>snapshots</id>
+ <url>https://oss.sonatype.org/content/repositories/snapshots</url>
+ <releases><enabled>false</enabled></releases>
+ </pluginRepository>
+ </pluginRepositories>
+
+</project>
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..6082a61
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2017-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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-dependencies</artifactId>
+ <version>1.10.6</version>
+ <relativePath></relativePath>
+ </parent>
+
+ <groupId>org.opencord</groupId>
+ <artifactId>ce</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <description>Carrier Ethernet service for CORD</description>
+
+ <properties>
+ <onos.app.category>Traffic Steering</onos.app.category>
+ <onos.app.url>http://opencord.org</onos.app.url>
+ </properties>
+
+ <modules>
+ <module>ce-api</module>
+ <module>local</module>
+ <module>global</module>
+ </modules>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.opencord</groupId>
+ <artifactId>cord-config</artifactId>
+ <version>1.4.0-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+ <repositories>
+ <repository>
+ <id>snapshots</id>
+ <url>https://oss.sonatype.org/content/repositories/snapshots</url>
+ <releases><enabled>false</enabled></releases>
+ </repository>
+ </repositories>
+
+ <pluginRepositories>
+ <pluginRepository>
+ <id>snapshots</id>
+ <url>https://oss.sonatype.org/content/repositories/snapshots</url>
+ <releases><enabled>false</enabled></releases>
+ </pluginRepository>
+ </pluginRepositories>
+
+</project>