New ONOS application for multicast and igmp provisioning with OVS.
This is required since ONOS is written to work only with OLT.
Changes to cord-test setup script to automatically start ONOS container if not running,
install the ciena ovs app for multicast and run the test.
diff --git a/src/test/apps/ciena-cordigmp-1.0-SNAPSHOT.oar b/src/test/apps/ciena-cordigmp-1.0-SNAPSHOT.oar
new file mode 100644
index 0000000..c2bd76c
--- /dev/null
+++ b/src/test/apps/ciena-cordigmp-1.0-SNAPSHOT.oar
Binary files differ
diff --git a/src/test/apps/ciena-cordigmp/pom.xml b/src/test/apps/ciena-cordigmp/pom.xml
new file mode 100644
index 0000000..7388237
--- /dev/null
+++ b/src/test/apps/ciena-cordigmp/pom.xml
@@ -0,0 +1,163 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright 2016 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>
+
+    <groupId>org.ciena.cordigmp</groupId>
+    <artifactId>ciena-cordigmp</artifactId>
+    <version>1.0-SNAPSHOT</version>
+    <packaging>bundle</packaging>
+
+    <description>Ciena CORD IGMP for OVS</description>
+    <url>http://onosproject.org</url>
+
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <onos.version>1.6.0-SNAPSHOT</onos.version>
+        <onos.app.name>org.ciena.cordigmp</onos.app.name>
+        <onos.app.title>Ciena IGMP for OVS</onos.app.title>
+        <onos.app.origin>Ciena Inc.</onos.app.origin>
+        <onos.app.category>default</onos.app.category>
+        <onos.app.url>http://onosproject.org</onos.app.url>
+        <onos.app.readme>ONOS OSGi bundle archetype.</onos.app.readme>
+    </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>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.12</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.12</version>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-cli</artifactId>
+            <version>1.6.0-SNAPSHOT</version>
+        </dependency>
+      <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+            <version>5.0.0</version>
+        </dependency>
+        <dependency>
+            <groupId>com.sun.jersey</groupId>
+            <artifactId>jersey-client</artifactId>
+            <version>1.19</version>
+        </dependency>
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-app-olt-api</artifactId>
+            <version>1.6.0-SNAPSHOT</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <version>3.0.1</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.21.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.9</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/src/test/apps/ciena-cordigmp/src/main/java/org/ciena/cordigmp/CordIgmp.java b/src/test/apps/ciena-cordigmp/src/main/java/org/ciena/cordigmp/CordIgmp.java
new file mode 100644
index 0000000..d3a515a
--- /dev/null
+++ b/src/test/apps/ciena-cordigmp/src/main/java/org/ciena/cordigmp/CordIgmp.java
@@ -0,0 +1,579 @@
+/*
+ * Copyright 2015-2016 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.ciena.cordigmp;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.ClientHandlerException;
+import com.sun.jersey.api.client.WebResource;
+import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+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.onlab.packet.Ethernet;
+import org.onlab.packet.IpAddress;
+import org.onosproject.cfg.ComponentConfigService;
+import org.onosproject.codec.CodecService;
+import org.onosproject.codec.JsonCodec;
+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.onosproject.net.config.basics.SubjectFactories;
+import org.onosproject.net.flow.DefaultTrafficSelector;
+import org.onosproject.net.flow.DefaultTrafficTreatment;
+import org.onosproject.net.flow.TrafficTreatment;
+import org.onosproject.net.flow.TrafficSelector;
+import org.onosproject.net.device.DeviceEvent;
+import org.onosproject.net.device.DeviceListener;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.flow.instructions.Instructions;
+import org.onosproject.net.flow.FlowEntry;
+import org.onosproject.net.flow.DefaultFlowEntry;
+import org.onosproject.net.flow.FlowRuleService;
+import org.onosproject.net.flowobjective.DefaultNextObjective;
+import org.onosproject.net.flowobjective.FlowObjectiveService;
+import org.onosproject.net.flowobjective.NextObjective;
+import org.onosproject.net.flowobjective.Objective;
+import org.onosproject.net.flowobjective.ObjectiveContext;
+import org.onosproject.net.flowobjective.ObjectiveError;
+import org.onosproject.net.mcast.McastEvent;
+import org.onosproject.net.mcast.McastListener;
+import org.onosproject.net.mcast.McastRoute;
+import org.onosproject.net.mcast.McastRouteInfo;
+import org.onosproject.net.mcast.MulticastRouteService;
+import org.onosproject.olt.AccessDeviceConfig;
+import org.onosproject.olt.AccessDeviceData;
+import org.onosproject.rest.AbstractWebResource;
+import org.osgi.service.component.ComponentContext;
+import org.onosproject.net.PortNumber;
+import org.onlab.packet.IPv4;
+import org.slf4j.Logger;
+
+import javax.ws.rs.core.MediaType;
+import java.io.IOException;
+import java.util.Dictionary;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Strings.isNullOrEmpty;
+import static com.google.common.net.MediaType.JSON_UTF_8;
+import static org.onlab.util.Tools.get;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * CORD multicast provisioning application. Operates by listening to
+ * events on the multicast rib and provisioning groups to program multicast
+ * flows on the dataplane.
+ */
+@Component(immediate = true)
+public class CordIgmp {
+
+
+    private static final int DEFAULT_REST_TIMEOUT_MS = 2000;
+    private static final int DEFAULT_PRIORITY = 500;
+    private static final short DEFAULT_MCAST_VLAN = 4000;
+    private static final String DEFAULT_SYNC_HOST = "localhost:8181";
+    private static final String DEFAULT_USER = "karaf";
+    private static final String DEFAULT_PASSWORD = "karaf";
+    private static final boolean DEFAULT_VLAN_ENABLED = true;
+    private static final short DEFAULT_INPUT_PORT = 2;
+    private static final short DEFAULT_OUTPUT_PORT = 1;
+    private final Logger log = getLogger(getClass());
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected MulticastRouteService mcastService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected FlowObjectiveService flowObjectiveService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected CoreService coreService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected CodecService codecService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected ComponentConfigService componentConfigService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected NetworkConfigRegistry networkConfig;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected FlowRuleService flowRuleService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected DeviceService deviceService;
+
+    protected McastListener listener = new InternalMulticastListener();
+    private InternalNetworkConfigListener configListener =
+            new InternalNetworkConfigListener();
+    private DeviceListener deviceListener = new InternalDeviceListener();
+
+    //TODO: move this to a ec map
+    private Map<IpAddress, Integer> groups = Maps.newConcurrentMap();
+
+    //TODO: move this to distributed atomic long
+    private AtomicInteger channels = new AtomicInteger(0);
+
+    private ApplicationId appId;
+
+    @Property(name = "mcastVlan", intValue = DEFAULT_MCAST_VLAN,
+            label = "VLAN for multicast traffic")
+    private int mcastVlan = DEFAULT_MCAST_VLAN;
+
+    @Property(name = "vlanEnabled", boolValue = DEFAULT_VLAN_ENABLED,
+            label = "Use vlan for multicast traffic?")
+    private boolean vlanEnabled = DEFAULT_VLAN_ENABLED;
+
+    @Property(name = "priority", intValue = DEFAULT_PRIORITY,
+            label = "Priority for multicast rules")
+    private int priority = DEFAULT_PRIORITY;
+
+    @Property(name = "syncHost", value = DEFAULT_SYNC_HOST,
+            label = "host:port to synchronize routes to")
+    private String syncHost = DEFAULT_SYNC_HOST;
+
+    @Property(name = "username", value = DEFAULT_USER,
+            label = "Username for REST password authentication")
+    private String user = DEFAULT_USER;
+
+    @Property(name = "password", value = DEFAULT_PASSWORD,
+            label = "Password for REST authentication")
+    private String password = DEFAULT_PASSWORD;
+
+    @Property(name = "inputPort", intValue = DEFAULT_INPUT_PORT,
+              label = "Input port for OVS multicast traffic")
+    private int inputPort = DEFAULT_INPUT_PORT;
+
+    @Property(name = "outputPort", intValue = DEFAULT_OUTPUT_PORT,
+              label = "Output port for OVS multicast traffic")
+    private int outputPort = DEFAULT_OUTPUT_PORT;
+
+    private String fabricOnosUrl;
+
+    private Map<DeviceId, AccessDeviceData> oltData = new ConcurrentHashMap<>();
+
+    private Map<DeviceId, Boolean> deviceAvailability = new ConcurrentHashMap<>();
+
+    private static final Class<AccessDeviceConfig> CONFIG_CLASS =
+            AccessDeviceConfig.class;
+
+    private ConfigFactory<DeviceId, AccessDeviceConfig> configFactory =
+            new ConfigFactory<DeviceId, AccessDeviceConfig>(
+                    SubjectFactories.DEVICE_SUBJECT_FACTORY, CONFIG_CLASS, "accessDevice") {
+                @Override
+                public AccessDeviceConfig createConfig() {
+                    return new AccessDeviceConfig();
+                }
+            };
+
+    @Activate
+    public void activate(ComponentContext context) {
+        componentConfigService.registerProperties(getClass());
+        modified(context);
+
+        appId = coreService.registerApplication("org.ciena.cordigmp");
+
+        clearRemoteRoutes();
+
+        networkConfig.registerConfigFactory(configFactory);
+        networkConfig.addListener(configListener);
+
+        networkConfig.getSubjects(DeviceId.class, AccessDeviceConfig.class).forEach(
+                subject -> {
+                    AccessDeviceConfig config = networkConfig.getConfig(subject, AccessDeviceConfig.class);
+                    if (config != null) {
+                        AccessDeviceData data = config.getOlt();
+                        oltData.put(data.deviceId(), data);
+                    }
+                }
+        );
+
+
+        mcastService.addListener(listener);
+
+        mcastService.getRoutes().stream()
+                .map(r -> new ImmutablePair<>(r, mcastService.fetchSinks(r)))
+                .filter(pair -> pair.getRight() != null && !pair.getRight().isEmpty())
+                .forEach(pair -> pair.getRight().forEach(sink -> provisionGroup(pair.getLeft(),
+                                                                                sink)));
+
+        deviceService.addListener(deviceListener);
+
+        log.info("Started");
+    }
+
+    @Deactivate
+    public void deactivate() {
+        componentConfigService.unregisterProperties(getClass(), false);
+        deviceService.removeListener(deviceListener);
+        mcastService.removeListener(listener);
+        networkConfig.unregisterConfigFactory(configFactory);
+        networkConfig.removeListener(configListener);
+        deviceAvailability.clear();
+        log.info("Stopped");
+    }
+
+    @Modified
+    public void modified(ComponentContext context) {
+        Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties();
+
+        try {
+            String s = get(properties, "username");
+            user = isNullOrEmpty(s) ? DEFAULT_USER : s.trim();
+
+            s = get(properties, "password");
+            password = isNullOrEmpty(s) ? DEFAULT_PASSWORD : s.trim();
+
+            s = get(properties, "mcastVlan");
+            mcastVlan = isNullOrEmpty(s) ? DEFAULT_MCAST_VLAN : Short.parseShort(s.trim());
+
+            s = get(properties, "vlanEnabled");
+            vlanEnabled = isNullOrEmpty(s) ? DEFAULT_VLAN_ENABLED : Boolean.parseBoolean(s.trim());
+
+            s = get(properties, "priority");
+            priority = isNullOrEmpty(s) ? DEFAULT_PRIORITY : Integer.parseInt(s.trim());
+
+            s = get(properties, "syncHost");
+            syncHost = isNullOrEmpty(s) ? DEFAULT_SYNC_HOST : s.trim();
+            log.warn("Sync Host = " + syncHost);
+
+            s = get(properties, "inputPort");
+            inputPort = isNullOrEmpty(s) ? DEFAULT_INPUT_PORT : Short.parseShort(s.trim());
+
+            s = get(properties, "outputPort");
+            outputPort = isNullOrEmpty(s) ? DEFAULT_OUTPUT_PORT : Short.parseShort(s.trim());
+
+        } catch (Exception e) {
+            user = DEFAULT_USER;
+            password = DEFAULT_PASSWORD;
+            syncHost = DEFAULT_SYNC_HOST;
+            mcastVlan = DEFAULT_MCAST_VLAN;
+            vlanEnabled = false;
+            priority = DEFAULT_PRIORITY;
+            inputPort = DEFAULT_INPUT_PORT;
+            outputPort = DEFAULT_OUTPUT_PORT;
+        }
+        fabricOnosUrl = createRemoteUrl(syncHost);
+    }
+
+    private static String createRemoteUrl(String remoteHost) {
+        return "http://" + remoteHost + "/onos/v1/mcast";
+    }
+
+    private class InternalMulticastListener implements McastListener {
+        @Override
+        public void event(McastEvent event) {
+            McastRouteInfo info = event.subject();
+            switch (event.type()) {
+                case ROUTE_ADDED:
+                    break;
+                case ROUTE_REMOVED:
+                    break;
+                case SOURCE_ADDED:
+                    break;
+                case SINK_ADDED:
+                    if (!info.sink().isPresent()) {
+                        log.warn("No sink given after sink added event: {}", info);
+                        return;
+                    }
+                    provisionGroup(info.route(), info.sink().get());
+                    break;
+                case SINK_REMOVED:
+                    unprovisionGroup(event.subject());
+                    break;
+                default:
+                    log.warn("Unknown mcast event {}", event.type());
+            }
+        }
+    }
+    
+    private void provisionFilterIgmp(DeviceId devId, boolean remove) {
+        Boolean deviceStatus = deviceAvailability.get(devId);
+        if(deviceStatus != null) {
+            if(remove == false) {
+                return;
+            }
+        } else if(remove == true) {
+            return;
+        }
+        TrafficSelector.Builder igmp = DefaultTrafficSelector.builder()
+            .matchEthType(Ethernet.TYPE_IPV4)
+            .matchIPProtocol(IPv4.PROTOCOL_IGMP);
+        TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder()
+            .setOutput(PortNumber.CONTROLLER);
+        FlowEntry.Builder flowEntry = DefaultFlowEntry.builder();
+        flowEntry.forDevice(devId);
+        flowEntry.withPriority(priority);
+        flowEntry.withSelector(igmp.build());
+        flowEntry.withTreatment(treatment.build());
+        flowEntry.fromApp(appId);
+        flowEntry.makePermanent();
+        if(remove == false) {
+            deviceAvailability.put(devId, true);
+            flowRuleService.applyFlowRules(flowEntry.build());
+        } else {
+            deviceAvailability.remove(devId);
+            flowRuleService.removeFlowRules(flowEntry.build());
+        }
+        log.warn("IGMP flow rule " + ( remove ? "removed" : "added" ) + " for device id " + devId);
+    }
+
+    private class InternalDeviceListener implements DeviceListener {
+        @Override
+        public void event(DeviceEvent event) {
+            DeviceId devId = event.subject().id();
+            switch (event.type()) {
+
+                case DEVICE_ADDED:
+                case DEVICE_UPDATED:
+                    provisionFilterIgmp(devId, false);
+                    break;
+                case DEVICE_AVAILABILITY_CHANGED:
+                    if(deviceService.isAvailable(devId)) {
+                        provisionFilterIgmp(devId, false);
+                    } else {
+                        provisionFilterIgmp(devId, true);
+                    }
+                    break;
+                case DEVICE_REMOVED:
+                case DEVICE_SUSPENDED:
+                    provisionFilterIgmp(devId, true);
+                    break;
+                case PORT_STATS_UPDATED:
+                case PORT_ADDED:
+                case PORT_UPDATED:
+                case PORT_REMOVED:
+                    //log.debug("Got event " + event.type() + " for device " + devId);
+                    break;
+                default:
+                    log.warn("Unknown device event {}", event.type());
+                    break;
+            }
+        }
+    }
+
+    private void unprovisionGroup(McastRouteInfo info) {
+        if (info.sinks().isEmpty()) {
+            removeRemoteRoute(info.route());
+        }
+
+        if (!info.sink().isPresent()) {
+            log.warn("No sink given after sink removed event: {}", info);
+            return;
+        }
+        ConnectPoint loc = info.sink().get();
+        AccessDeviceData oltInfo = oltData.get(loc.deviceId());
+        if(oltInfo != null) {
+            log.warn("Ignoring deprovisioning mcast route for OLT device: " + loc.deviceId());
+            return;
+        }
+        log.warn("Unknown OLT device for unprovisioning. Assuming OVS {}", loc.deviceId());
+        final PortNumber inPort = PortNumber.portNumber(inputPort);
+        final PortNumber outPort = PortNumber.portNumber(outputPort);
+        TrafficSelector.Builder mcast = DefaultTrafficSelector.builder()
+            .matchInPort(inPort)
+            .matchEthType(Ethernet.TYPE_IPV4)
+            .matchIPDst(info.route().group().toIpPrefix());
+        TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
+        FlowEntry.Builder flowEntry = DefaultFlowEntry.builder();
+        treatment.add(Instructions.createOutput(outPort));
+        flowEntry.forDevice(loc.deviceId());
+        flowEntry.withPriority(priority);
+        flowEntry.withSelector(mcast.build());
+        flowEntry.withTreatment(treatment.build());
+        flowEntry.fromApp(appId);
+        flowEntry.makePermanent();
+        flowRuleService.removeFlowRules(flowEntry.build());
+        groups.remove(info.route().group());
+        log.warn("Flow rule removed for for device id " + loc.deviceId());
+        return;
+    }
+
+    private void provisionGroup(McastRoute route, ConnectPoint sink) {
+        checkNotNull(route, "Route cannot be null");
+        checkNotNull(sink, "Sink cannot be null");
+
+        AccessDeviceData oltInfo = oltData.get(sink.deviceId());
+        final AtomicBoolean sync = new AtomicBoolean(false);
+        if(oltInfo != null) {
+            log.warn("Ignoring provisioning mcast route for OLT device: " + sink.deviceId());
+            return;
+        } 
+
+        Integer ret = groups.computeIfAbsent(route.group(), (g) -> {
+            final PortNumber inPort = PortNumber.portNumber(inputPort);
+            final PortNumber outPort = PortNumber.portNumber(outputPort);
+            TrafficSelector.Builder mcast = DefaultTrafficSelector.builder()
+                    .matchInPort(inPort)
+                    .matchEthType(Ethernet.TYPE_IPV4)
+                    .matchIPDst(g.toIpPrefix());
+            TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
+            FlowEntry.Builder flowEntry = DefaultFlowEntry.builder();
+            treatment.add(Instructions.createOutput(outPort));
+            flowEntry.forDevice(sink.deviceId());
+            flowEntry.withPriority(priority);
+            flowEntry.withSelector(mcast.build());
+            flowEntry.withTreatment(treatment.build());
+            flowEntry.fromApp(appId);
+            flowEntry.makePermanent();
+            flowRuleService.applyFlowRules(flowEntry.build());
+            log.warn("Flow rules applied for device id " + sink.deviceId());
+            return 0;
+        });
+        if (ret == 0) {
+            addRemoteRoute(route);
+        }
+    }
+
+    private void addRemoteRoute(McastRoute route) {
+        checkNotNull(route);
+        if (syncHost == null) {
+            log.warn("No host configured for synchronization; route will be dropped");
+            return;
+        }
+
+        log.warn("Sending routes {} to other ONOS {}", route, fabricOnosUrl);
+
+        WebResource.Builder builder = getClientBuilder(fabricOnosUrl);
+
+        ObjectNode json = codecService.getCodec(McastRoute.class)
+                .encode(route, new AbstractWebResource());
+
+        try {
+            builder.post(json.toString());
+        } catch (ClientHandlerException e) {
+            log.warn("Unable to send route to remote controller: {}", e.getMessage());
+        }
+    }
+
+    private void removeRemoteRoute(McastRoute route) {
+        if (syncHost == null) {
+            log.warn("No host configured for synchronization; route will be dropped");
+            return;
+        }
+
+        log.debug("Removing route {} from other ONOS {}", route, fabricOnosUrl);
+
+        WebResource.Builder builder = getClientBuilder(fabricOnosUrl);
+
+        ObjectNode json = codecService.getCodec(McastRoute.class)
+                .encode(route, new AbstractWebResource());
+        try {
+            builder.delete(json.toString());
+        } catch (ClientHandlerException e) {
+            log.warn("Unable to delete route from remote controller: {}", e.getMessage());
+        }
+    }
+
+    private void clearRemoteRoutes() {
+        if (syncHost == null) {
+            log.warn("No host configured for synchronization");
+            return;
+        }
+
+        log.debug("Clearing remote multicast routes from {}", fabricOnosUrl);
+
+        WebResource.Builder builder = getClientBuilder(fabricOnosUrl);
+        List<McastRoute> mcastRoutes = Lists.newArrayList();
+
+        try {
+            String response = builder
+                    .accept(MediaType.APPLICATION_JSON_TYPE)
+                    .get(String.class);
+
+            JsonCodec<McastRoute> routeCodec = codecService.getCodec(McastRoute.class);
+            ObjectMapper mapper = new ObjectMapper();
+
+
+            ObjectNode node = (ObjectNode) mapper.readTree(response);
+            ArrayNode list = (ArrayNode) node.path("routes");
+
+            list.forEach(n -> mcastRoutes.add(
+                    routeCodec.decode((ObjectNode) n, new AbstractWebResource())));
+
+        } catch (ClientHandlerException e) {
+            log.warn("Unable to clear routes from remote controller: {}", e.getMessage());
+        } catch (IOException e) {
+            log.warn("Error clearing remote routes", e);
+        }
+
+        mcastRoutes.forEach(this::removeRemoteRoute);
+    }
+
+    private WebResource.Builder getClientBuilder(String uri) {
+        Client client = Client.create();
+        client.setConnectTimeout(DEFAULT_REST_TIMEOUT_MS);
+        client.setReadTimeout(DEFAULT_REST_TIMEOUT_MS);
+        client.addFilter(new HTTPBasicAuthFilter(user, password));
+        WebResource resource = client.resource(uri);
+        return resource.accept(JSON_UTF_8.toString())
+                .type(JSON_UTF_8.toString());
+    }
+
+    private class InternalNetworkConfigListener implements NetworkConfigListener {
+        @Override
+        public void event(NetworkConfigEvent event) {
+            switch (event.type()) {
+
+                case CONFIG_ADDED:
+                case CONFIG_UPDATED:
+                    AccessDeviceConfig config =
+                            networkConfig.getConfig((DeviceId) event.subject(), CONFIG_CLASS);
+                    if (config != null) {
+                        oltData.put(config.getOlt().deviceId(), config.getOlt());
+                    }
+
+                    break;
+                case CONFIG_REGISTERED:
+                case CONFIG_UNREGISTERED:
+                    break;
+                case CONFIG_REMOVED:
+                    oltData.remove(event.subject());
+                    break;
+                default:
+                    break;
+            }
+        }
+
+        @Override
+        public boolean isRelevant(NetworkConfigEvent event) {
+            return event.configClass().equals(CONFIG_CLASS);
+        }
+
+
+    }
+
+}
diff --git a/src/test/setup/cord-test.sh b/src/test/setup/cord-test.sh
index a6b743e..0cc65e6 100755
--- a/src/test/setup/cord-test.sh
+++ b/src/test/setup/cord-test.sh
@@ -1,7 +1,7 @@
 #!/usr/bin/env bash
 
 function show_help {
-    echo "Usage: ${0#*/} -h | this help -n <onos_ip> -r <radius_ip> -o <onos cnt image> -a <radius cnt image> -t <test type> -c | cleanup test containers -C <cleanup container list> -k | kill the test container -b <test cnt image> | build test container docker image"
+    echo "Usage: ${0#*/} -h | this help -n <onos_ip> -r <radius_ip> -o <onos cnt image> -a < onos app file> -d <radius cnt image> -t <test type> -c | cleanup test containers -C <cleanup container list> -k | kill the test container -b <test cnt image> | build test container docker image"
     exit 1
 }
 
@@ -13,8 +13,21 @@
     echo $ipaddr
 }
 
+function onos_start {
+    local image="${1}"
+    local port_str=""
+    for p in 8181 8101 9876 6653 6633; do
+        port_str="$port_str -p $p:$p/tcp"
+    done
+    ONOS_APPS="drivers,openflow,proxyarp,mobility,fwd,aaa,igmp"
+    local cnt=`docker run -itd $port_str -e ONOS_APPS=${ONOS_APPS} $image /bin/bash`
+    local ipaddr
+    ipaddr=`docker inspect -f '{{.NetworkSettings.IPAddress}}' $cnt`
+    echo $ipaddr
+}
+
 test_type=dhcp
-onos_cnt_image=onos:igmp-test
+onos_cnt_image=onosproject/onos
 radius_cnt_image=radius-server:dev
 onos_ip=
 radius_ip=
@@ -24,8 +37,10 @@
 kill_test_cnt=0
 build_cnt_image=
 cleanup_cnt_list=
+app_version=1.0-SNAPSHOT
+onos_app_file=$PWD/../apps/ciena-cordigmp-$app_version.oar
 
-while getopts "h?n:r:o:a:t:cC:kb:" opt; do 
+while getopts "h?a:n:r:o:d:t:cC:kb:" opt; do 
     case "$opt" in
         h|\?)
             show_help
@@ -43,9 +58,12 @@
         o)
             onos_cnt_image=$OPTARG
             ;;
-        a)
+        d)
             radius_cnt_image=$OPTARG
             ;;
+        a)
+            onos_app_file=$OPTARG
+            ;;
         c)
             cleanup=1
             ;;
@@ -87,7 +105,23 @@
 fi
 
 if [ x"$onos_ip" = "x" ]; then
+    ##First try fetching the existing ip for onos container
     onos_ip=$(cnt_ipaddr $onos_cnt_image)
+    ##If we find no onos running, then spawn the container if we can
+    if [ x"$onos_ip" = "x" ]; then
+        ##If the container image is from onosproject, we can try starting it
+        if [[ "$onos_cnt_image" =~ "onosproject/" ]]; then
+            echo "Starting ONOS container $onos_cnt_image"
+            onos_ip=$(onos_start $onos_cnt_image)
+            echo "Waiting 60 seconds for ONOS to fully boot up"
+            sleep 60
+        fi
+    fi
+fi
+
+if [ x"$onos_ip" = "x" ]; then
+    echo "ONOS not running or container name is invalid"
+    exit 127
 fi
 
 if [ x"$radius_ip" = "x" ]; then
@@ -104,6 +138,18 @@
     echo "Done building docker image $build_cnt_image"
     nose_cnt_image=$build_cnt_image
 fi
+
+function install_onos_app {
+    local app=$1
+    local onos_url="http://$onos_ip:8181/onos/v1/applications"
+    local curl="curl -sS --user karaf:karaf"
+    $curl -X POST -HContent-Type:application/octet-stream $onos_url?activate=true --data-binary @$app
+}
+
+echo "Installing and activating onos app $onos_app_file"
+
+install_onos_app $onos_app_file
+
 echo "Starting test container $nose_cnt_image"
 
 test_cnt=`docker run -itd --privileged -v $HOME/nose_exp:/root/test -v /lib/modules:/lib/modules -e ONOS_CONTROLLER_IP=$onos_ip -e ONOS_AAA_IP=$radius_ip $nose_cnt_image /bin/bash`
diff --git a/src/test/subscriber/subscriberDb.py b/src/test/subscriber/subscriberDb.py
index d6b3f75..89fcc5c 100644
--- a/src/test/subscriber/subscriberDb.py
+++ b/src/test/subscriber/subscriberDb.py
@@ -7,7 +7,7 @@
         self.con = sqlite3.connect(db)
         self.con.row_factory = sqlite3.Row
         self.cur = self.con.cursor()
-        self.services = [ 'DHCP', 'IGMP' ]
+        self.services = [ 'TLS', 'DHCP', 'IGMP' ]
         self.create = create
         if create == True:
             self.cur.execute("DROP TABLE IF EXISTS Subscriber")