Skeleton E-CORD app (CO side). Bigswitch abstraction service.

ONOS-1081

Change-Id: I2c4e4ede477da73bfc98d61ecc145f2400f146a8
diff --git a/ecord/co/pom.xml b/ecord/co/pom.xml
new file mode 100644
index 0000000..733b7a8
--- /dev/null
+++ b/ecord/co/pom.xml
@@ -0,0 +1,149 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright 2015 Open Networking Laboratory
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+<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>
+        <artifactId>onos-app-samples</artifactId>
+        <groupId>org.onosproject</groupId>
+        <version>1.4.0-SNAPSHOT</version>
+        <relativePath>../../pom.xml</relativePath>
+    </parent>
+
+    <groupId>org.onosproject</groupId>
+    <artifactId>onos-app-ecord-co</artifactId>
+    <version>1.4.0-SNAPSHOT</version>
+    <packaging>bundle</packaging>
+
+    <description>Enterprise CORD for Central Office</description>
+    <url>http://onosproject.org</url>
+
+    <properties>
+        <onos.version>1.4.0-SNAPSHOT</onos.version>
+        <onos.app.name>org.onosproject.ecord.co</onos.app.name>
+        <onos.app.origin>Open Networking Lab</onos.app.origin>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-api</artifactId>
+            <version>${onos.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onlab-osgi</artifactId>
+            <version>${onos.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-core-dist</artifactId>
+            <version>${onos.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.11</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-api</artifactId>
+            <version>${onos.version}</version>
+            <scope>test</scope>
+            <classifier>tests</classifier>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.scr.annotations</artifactId>
+            <version>1.9.8</version>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <version>2.5.3</version>
+                <extensions>true</extensions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>2.5.1</version>
+                <configuration>
+                    <source>1.8</source>
+                    <target>1.8</target>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-scr-plugin</artifactId>
+                <version>1.20.0</version>
+                <executions>
+                    <execution>
+                        <id>generate-scr-srcdescriptor</id>
+                        <goals>
+                            <goal>scr</goal>
+                        </goals>
+                    </execution>
+                </executions>
+                <configuration>
+                    <supportedProjectTypes>
+                        <supportedProjectType>bundle</supportedProjectType>
+                        <supportedProjectType>war</supportedProjectType>
+                    </supportedProjectTypes>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.onosproject</groupId>
+                <artifactId>onos-maven-plugin</artifactId>
+                <version>1.5</version>
+                <executions>
+                    <execution>
+                        <id>cfg</id>
+                        <phase>generate-resources</phase>
+                        <goals>
+                            <goal>cfg</goal>
+                        </goals>
+                    </execution>
+                    <execution>
+                        <id>swagger</id>
+                        <phase>generate-sources</phase>
+                        <goals>
+                            <goal>swagger</goal>
+                        </goals>
+                    </execution>
+                    <execution>
+                        <id>app</id>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>app</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
diff --git a/ecord/co/src/main/java/org/onosproject/ecord/co/BigSwitch.java b/ecord/co/src/main/java/org/onosproject/ecord/co/BigSwitch.java
new file mode 100644
index 0000000..7d6c0ab
--- /dev/null
+++ b/ecord/co/src/main/java/org/onosproject/ecord/co/BigSwitch.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.ecord.co;
+
+import org.onlab.packet.ChassisId;
+import org.onosproject.net.DefaultDevice;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.provider.ProviderId;
+
+/**
+ * Convenience class for big switch devices.
+ */
+public class BigSwitch extends DefaultDevice {
+    private static final String ONLAB_MANUFACTURER = "ON.Lab";
+    private static final String HW_VERSION = "CORD BigSwitch";
+    private static final String SW_VERSION = "v1";
+    private static final String SERIAL = "v1";
+    private static final ChassisId CHASSIS = new ChassisId();
+
+    /**
+     * Creates a big switch instance with given device ID and provider ID.
+     *
+     * @param deviceId the device ID
+     * @param providerId the provider ID
+     */
+    public BigSwitch(DeviceId deviceId, ProviderId providerId) {
+        super(providerId, deviceId, Type.VIRTUAL, ONLAB_MANUFACTURER, HW_VERSION, SW_VERSION, SERIAL, CHASSIS);
+    }
+}
diff --git a/ecord/co/src/main/java/org/onosproject/ecord/co/BigSwitchDeviceProvider.java b/ecord/co/src/main/java/org/onosproject/ecord/co/BigSwitchDeviceProvider.java
new file mode 100644
index 0000000..ce0bf3f
--- /dev/null
+++ b/ecord/co/src/main/java/org/onosproject/ecord/co/BigSwitchDeviceProvider.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.ecord.co;
+
+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.incubator.rpc.RemoteServiceContext;
+import org.onosproject.incubator.rpc.RemoteServiceDirectory;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.MastershipRole;
+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.provider.AbstractProvider;
+import org.onosproject.net.provider.ProviderId;
+import org.slf4j.Logger;
+
+import java.net.URI;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Device provider which exposes a big switch abstraction of the underlying data path.
+ */
+@Component(immediate = true)
+public class BigSwitchDeviceProvider extends AbstractProvider implements DeviceProvider {
+
+    private static final Logger LOG = getLogger(BigSwitchDeviceProvider.class);
+
+    private static final String SCHEME = "bigswitch";
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected BigSwitchService bigSwitchService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected ClusterService clusterService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected RemoteServiceDirectory rpcService;
+
+    private BigSwitch bigSwitch;
+    private DeviceDescription bigSwitchDescription;
+    private DeviceProviderRegistry providerRegistry;
+    private DeviceProviderService providerService;
+    private BigSwitchListener listener = new InternalListener();
+
+    @Activate
+    public void activate() {
+        // Create big switch device and description
+        DeviceId deviceId = DeviceId.deviceId(SCHEME + ':' + clusterService.getLocalNode().ip());
+        bigSwitch = new BigSwitch(deviceId, this.id());
+        buildDeviceDescription();
+        // Register this device provider remotely
+        // TODO: make remote configurable
+        RemoteServiceContext remoteServiceContext = rpcService.get(URI.create("local://localhost"));
+        providerRegistry = remoteServiceContext.get(DeviceProviderRegistry.class);
+        providerService = providerRegistry.register(this);
+        // Start big switch service and register device
+        bigSwitchService.addListener(listener);
+        registerDevice();
+        LOG.info("Started");
+    }
+
+    @Deactivate
+    public void deactivate() {
+        unregisterDevice();
+        providerRegistry.unregister(this);
+        // Won't hurt but necessary?
+        providerService = null;
+        LOG.info("Stopped");
+    }
+
+    private void registerDevice() {
+        providerService.deviceConnected(bigSwitch.id(), bigSwitchDescription);
+        providerService.updatePorts(bigSwitch.id(), bigSwitchService.getPorts());
+    }
+
+    private void unregisterDevice() {
+        providerService.deviceDisconnected(bigSwitch.id());
+    }
+
+    private class InternalListener implements BigSwitchListener {
+        @Override
+        public void event(BigSwitchEvent event) {
+            switch (event.type()) {
+                case PORT_ADDED:
+                case PORT_REMOVED:
+                    providerService.updatePorts(bigSwitch.id(), bigSwitchService.getPorts());
+                    break;
+                case PORT_UPDATED:
+                    providerService.portStatusChanged(bigSwitch.id(), event.subject());
+                    break;
+                default:
+                    break;
+            }
+        }
+    }
+
+    private void buildDeviceDescription() {
+        bigSwitchDescription = new DefaultDeviceDescription(bigSwitch.id().uri(),
+                bigSwitch.type(), bigSwitch.manufacturer(),
+                bigSwitch.hwVersion(), bigSwitch.swVersion(), bigSwitch.serialNumber(), bigSwitch.chassisId());
+    }
+
+    /**
+     * A big switch device provider implementation.
+     */
+    public BigSwitchDeviceProvider() {
+        super(new ProviderId(SCHEME, "org.onosproject.bigswitch"));
+    }
+
+    @Override
+    public void triggerProbe(DeviceId deviceId) {
+    }
+
+    @Override
+    public void roleChanged(DeviceId deviceId, MastershipRole newRole) {
+    }
+
+    @Override
+    public boolean isReachable(DeviceId deviceId) {
+        return true;
+    }
+}
diff --git a/ecord/co/src/main/java/org/onosproject/ecord/co/BigSwitchEvent.java b/ecord/co/src/main/java/org/onosproject/ecord/co/BigSwitchEvent.java
new file mode 100644
index 0000000..4a1252e
--- /dev/null
+++ b/ecord/co/src/main/java/org/onosproject/ecord/co/BigSwitchEvent.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.ecord.co;
+
+import org.onosproject.event.AbstractEvent;
+import org.onosproject.net.device.PortDescription;
+
+public class BigSwitchEvent extends AbstractEvent<BigSwitchEvent.Type, PortDescription> {
+
+    public enum Type {
+        /**
+         * 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
+     */
+    public BigSwitchEvent(Type type, PortDescription subject) {
+        super(type, subject);
+    }
+
+    /**
+     * Creates a new big switch event.
+     *
+     * @param type event type
+     * @param subject the port description
+     * @param time occurence time
+     */
+    public BigSwitchEvent(Type type, PortDescription subject, long time) {
+        super(type, subject, time);
+    }
+}
diff --git a/ecord/co/src/main/java/org/onosproject/ecord/co/BigSwitchListener.java b/ecord/co/src/main/java/org/onosproject/ecord/co/BigSwitchListener.java
new file mode 100644
index 0000000..bd8c64c
--- /dev/null
+++ b/ecord/co/src/main/java/org/onosproject/ecord/co/BigSwitchListener.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.ecord.co;
+
+import org.onosproject.event.EventListener;
+
+/**
+ * Component to inform about big switch updates.
+ */
+public interface BigSwitchListener extends EventListener<BigSwitchEvent> {
+}
diff --git a/ecord/co/src/main/java/org/onosproject/ecord/co/BigSwitchManager.java b/ecord/co/src/main/java/org/onosproject/ecord/co/BigSwitchManager.java
new file mode 100644
index 0000000..d90af33
--- /dev/null
+++ b/ecord/co/src/main/java/org/onosproject/ecord/co/BigSwitchManager.java
@@ -0,0 +1,206 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.ecord.co;
+
+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.event.AbstractListenerManager;
+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.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.edge.EdgePortEvent;
+import org.onosproject.net.edge.EdgePortListener;
+import org.onosproject.net.edge.EdgePortService;
+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.slf4j.Logger;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+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(BigSwitchDeviceProvider.class);
+
+    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);
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected DeviceService deviceService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected EdgePortService edgePortService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected StorageService storageService;
+
+    // Holds the physical port to virtual port number mapping
+    private ConsistentMap<ConnectPoint, Long> portMap;
+    // Counter for virtual port numbers
+    private AtomicCounter portCounter;
+    // TODO: Add other listeners once we decide what an edge really is
+    private EdgePortListener edgeListener = new InternalEdgeListener();
+    private DeviceListener deviceListener = new InternalDeviceListener();
+
+    @Activate
+    public void activate() {
+        portMap = storageService.<ConnectPoint, Long>consistentMapBuilder()
+                .withName(PORT_MAP)
+                .withSerializer(SERIALIZER)
+                .build();
+        portCounter = storageService.atomicCounterBuilder()
+                .withName(PORT_COUNTER)
+                .withMeteringDisabled()
+                .build();
+        eventDispatcher.addSink(BigSwitchEvent.class, listenerRegistry);
+        //portCounter.compareAndSet(0, 1);     // Start counting from 1, doesn't work??
+        buildPorts();
+        edgePortService.addListener(edgeListener);
+        deviceService.addListener(deviceListener);
+        log.info("Started");
+    }
+
+    @Deactivate
+    public void deactivate() {
+        edgePortService.removeListener(edgeListener);
+        deviceService.removeListener(deviceListener);
+        log.info("Stopped");
+    }
+
+    @Override
+    public List<PortDescription> getPorts() {
+        return portMap.keySet().stream()
+                .map(cp -> toPortDescription(cp))
+                .collect(Collectors.toList());
+    }
+
+    /**
+     * Convert connect point to port description.
+     *
+     * @param cp connect point
+     * @return port description
+     */
+    private PortDescription toPortDescription(ConnectPoint cp) {
+        Port p = deviceService.getPort(cp.deviceId(), cp.port());
+        // This is annoying
+        DefaultAnnotations.Builder annot = DefaultAnnotations.builder();
+        p.annotations().keys()
+                .forEach(k -> annot.set(k, p.annotations().value(k)));
+
+        return new DefaultPortDescription(
+                PortNumber.portNumber(portMap.get(cp).value()),
+                p.isEnabled(),
+                p.type(),
+                p.portSpeed(),
+                annot.build()
+        );
+    }
+
+    private class InternalEdgeListener implements EdgePortListener {
+        @Override
+        public boolean isRelevant(EdgePortEvent event) {
+            // Only listen for real devices
+            Device d = deviceService.getDevice(event.subject().deviceId());
+
+            return !d.type().equals(Device.Type.VIRTUAL);
+        }
+
+        @Override
+        public void event(EdgePortEvent event) {
+            log.debug("Edge event {} {}", event.subject(), event.type());
+            BigSwitchEvent.Type bigSwitchEvent;
+
+            switch (event.type()) {
+                case EDGE_PORT_ADDED:
+                    portMap.put(event.subject(), portCounter.getAndIncrement());
+                    bigSwitchEvent = BigSwitchEvent.Type.PORT_ADDED;
+                    break;
+                case EDGE_PORT_REMOVED:
+                    portMap.remove(event.subject());
+                    bigSwitchEvent = BigSwitchEvent.Type.PORT_REMOVED;
+                    break;
+                default:
+                    return;
+            }
+
+            post(new BigSwitchEvent(bigSwitchEvent, toPortDescription(event.subject())));
+        }
+    }
+
+    private class InternalDeviceListener implements DeviceListener {
+        @Override
+        public boolean isRelevant(DeviceEvent event) {
+            // Only listen for real devices
+            return !event.subject().type().equals(Device.Type.VIRTUAL);
+        }
+
+        @Override
+        public void event(DeviceEvent event) {
+            log.debug("Device event {} {} {}", event.subject(), event.port(), event.type());
+
+            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:
+                case PORT_REMOVED:
+                case PORT_STATS_UPDATED:
+                    break;
+                case PORT_UPDATED:
+                    // Update if state of existing edge changed
+                    ConnectPoint cp = new ConnectPoint(event.subject().id(), event.port().number());
+                    if (portMap.containsKey(cp)) {
+                        post(new BigSwitchEvent(BigSwitchEvent.Type.PORT_UPDATED, toPortDescription(cp)));
+                    }
+                    break;
+                default:
+                    break;
+            }
+        }
+    }
+
+    private void buildPorts() {
+        edgePortService.getEdgePoints()
+                .forEach(cp -> portMap.put(cp, portCounter.getAndIncrement()));
+    }
+}
diff --git a/ecord/co/src/main/java/org/onosproject/ecord/co/BigSwitchService.java b/ecord/co/src/main/java/org/onosproject/ecord/co/BigSwitchService.java
new file mode 100644
index 0000000..0997e61
--- /dev/null
+++ b/ecord/co/src/main/java/org/onosproject/ecord/co/BigSwitchService.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.ecord.co;
+
+import org.onosproject.event.ListenerService;
+import org.onosproject.net.device.PortDescription;
+
+import java.util.List;
+
+/**
+ * Service to interact with big switch abstraction.
+ */
+public interface BigSwitchService extends ListenerService<BigSwitchEvent, BigSwitchListener> {
+    /**
+     * Get list of big switch ports.
+     *
+     * @return list of port descriptions
+     */
+    List<PortDescription> getPorts();
+}
diff --git a/ecord/co/src/main/java/org/onosproject/ecord/co/CentralOffice.java b/ecord/co/src/main/java/org/onosproject/ecord/co/CentralOffice.java
new file mode 100644
index 0000000..0d1714a
--- /dev/null
+++ b/ecord/co/src/main/java/org/onosproject/ecord/co/CentralOffice.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.ecord.co;
+
+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.net.device.DeviceProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Enterprise CORD application for Central Office side.
+ *
+ * Ties together a gRPC-based big switch device provider,
+ * along with a to-be-developed link provider, and gRPC-based CORD API
+ * to control segment routing and vRouter.
+ */
+@Component(immediate = true)
+public class CentralOffice {
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private static final String ECORD_CO_APP = "org.onosproject.ecord.co";
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected CoreService coreService;
+
+    private DeviceProvider deviceProvider = new BigSwitchDeviceProvider();
+
+    @Activate
+    protected void activate() {
+        coreService.registerApplication(ECORD_CO_APP);
+        log.info("Enterprise CORD for central office started");
+    }
+
+    @Deactivate
+    protected void deactivate() {
+        log.info("Enterprise CORD for central office stopped");
+    }
+}
diff --git a/ecord/co/src/main/java/org/onosproject/ecord/co/package-info.java b/ecord/co/src/main/java/org/onosproject/ecord/co/package-info.java
new file mode 100644
index 0000000..e0c21f1
--- /dev/null
+++ b/ecord/co/src/main/java/org/onosproject/ecord/co/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Enterprise CORD for Central Office application.
+ */
+package org.onosproject.ecord.co;
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 50202c1..a2cc2ea 100644
--- a/pom.xml
+++ b/pom.xml
@@ -13,10 +13,7 @@
   ~ 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">
+  --><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>
@@ -57,7 +54,8 @@
         <module>oneping</module>
         <module>tvue</module>
         <module>uiref</module>
-    </modules>
+        <module>ecord/co</module>
+  </modules>
 
     <properties>
         <web.context>default</web.context>