Porting CE app to 4.1

Change-Id: Ic3280ce797f6225773ade789d9793ae445f9f525
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>