adding iptv provisioning

Change-Id: I11fcc788402793d0bf3ac9d9f03ed77e093d98ad
diff --git a/apps/cordfabric/src/main/java/org/onosproject/cordfabric/CordFabricManager.java b/apps/cordfabric/src/main/java/org/onosproject/cordfabric/CordFabricManager.java
index f3bd96c..ab31aee 100644
--- a/apps/cordfabric/src/main/java/org/onosproject/cordfabric/CordFabricManager.java
+++ b/apps/cordfabric/src/main/java/org/onosproject/cordfabric/CordFabricManager.java
@@ -168,6 +168,8 @@
                 .withTreatment(down)
                 .add();
 
+
+
         flowObjectiveService.forward(fabricDeviceId, upCtrl);
         flowObjectiveService.forward(fabricDeviceId, downCtrl);
         flowObjectiveService.forward(fabricDeviceId, radiusToController);
@@ -181,6 +183,10 @@
 
         removeVlan(vlan.vlan());
 
+        if (vlan.iptv()) {
+            provisionIPTV();
+        }
+
         vlan.ports().forEach(cp -> {
             if (vlans.put(vlan.vlan(), cp)) {
                 addForwarding(vlan.vlan(), cp.deviceId(), cp.port(),
@@ -192,6 +198,46 @@
         });
     }
 
+    //FIXME: pass iptv vlan in here.
+    private void provisionIPTV() {
+        TrafficSelector ipTvUp = DefaultTrafficSelector.builder()
+                .matchVlanId(VlanId.vlanId((short) 7))
+                .matchInPort(PortNumber.portNumber(2))
+                .build();
+
+        TrafficTreatment ipTvActUp = DefaultTrafficTreatment.builder()
+                .setOutput(PortNumber.portNumber(7)).build();
+
+        TrafficSelector ipTvDown = DefaultTrafficSelector.builder()
+                .matchVlanId(VlanId.vlanId((short) 7))
+                .matchInPort(PortNumber.portNumber(7))
+                .build();
+
+        TrafficTreatment ipTvActDown = DefaultTrafficTreatment.builder()
+                .setOutput(PortNumber.portNumber(2)).build();
+
+        ForwardingObjective ipTvUpstream = DefaultForwardingObjective.builder()
+                .fromApp(appId)
+                .makePermanent()
+                .withFlag(ForwardingObjective.Flag.VERSATILE)
+                .withPriority(PRIORITY)
+                .withSelector(ipTvUp)
+                .withTreatment(ipTvActUp)
+                .add();
+
+        ForwardingObjective ipTvDownstream = DefaultForwardingObjective.builder()
+                .fromApp(appId)
+                .makePermanent()
+                .withFlag(ForwardingObjective.Flag.VERSATILE)
+                .withPriority(PRIORITY)
+                .withSelector(ipTvDown)
+                .withTreatment(ipTvActDown)
+                .add();
+
+        flowObjectiveService.forward(fabricDeviceId, ipTvUpstream);
+        flowObjectiveService.forward(fabricDeviceId, ipTvDownstream);
+    }
+
     @Override
     public void removeVlan(VlanId vlanId) {
         vlans.removeAll(vlanId)
@@ -202,7 +248,9 @@
     public List<FabricVlan> getVlans() {
         List<FabricVlan> fVlans = new ArrayList<>();
         vlans.keySet().forEach(vlan -> fVlans.add(
-                new FabricVlan(vlan, vlans.get(vlan))));
+                //FIXME: Very aweful but will fo for now
+                new FabricVlan(vlan, vlans.get(vlan),
+                               vlan.toShort() == 201 ? true : false)));
         return fVlans;
     }
 
@@ -217,6 +265,7 @@
 
     private void addForwarding(VlanId vlanId, DeviceId deviceId, PortNumber inPort,
                                List<PortNumber> outPorts) {
+
         TrafficSelector selector = DefaultTrafficSelector.builder()
                 .matchVlanId(vlanId)
                 .matchInPort(inPort)
diff --git a/apps/cordfabric/src/main/java/org/onosproject/cordfabric/FabricVlan.java b/apps/cordfabric/src/main/java/org/onosproject/cordfabric/FabricVlan.java
index d145928..a5cfc07 100644
--- a/apps/cordfabric/src/main/java/org/onosproject/cordfabric/FabricVlan.java
+++ b/apps/cordfabric/src/main/java/org/onosproject/cordfabric/FabricVlan.java
@@ -33,12 +33,14 @@
     private final VlanId vlan;
 
     private final List<ConnectPoint> ports;
+    private final boolean iptv;
 
-    public FabricVlan(VlanId vlan, Collection<ConnectPoint> ports) {
+    public FabricVlan(VlanId vlan, Collection<ConnectPoint> ports, boolean iptv) {
         checkNotNull(vlan);
         checkNotNull(ports);
         this.vlan = vlan;
         this.ports = ImmutableList.copyOf(ports);
+        this.iptv = iptv;
     }
 
     public VlanId vlan() {
@@ -48,4 +50,8 @@
     public List<ConnectPoint> ports() {
         return ports;
     }
+
+    public boolean iptv() {
+        return iptv;
+    }
 }
diff --git a/apps/cordfabric/src/main/java/org/onosproject/cordfabric/FabricVlanCodec.java b/apps/cordfabric/src/main/java/org/onosproject/cordfabric/FabricVlanCodec.java
index 0a097b2..00736bc 100644
--- a/apps/cordfabric/src/main/java/org/onosproject/cordfabric/FabricVlanCodec.java
+++ b/apps/cordfabric/src/main/java/org/onosproject/cordfabric/FabricVlanCodec.java
@@ -37,6 +37,7 @@
     // JSON field names
     private static final String VLAN = "vlan";
     private static final String PORTS = "ports";
+    private static final String IPTV = "iptv";
 
     @Override
     public ObjectNode encode(FabricVlan vlan, CodecContext context) {
@@ -54,6 +55,7 @@
     @Override
     public FabricVlan decode(ObjectNode json, CodecContext context) {
         short vlan =  json.path(VLAN).shortValue();
+        boolean iptv = json.path(IPTV).booleanValue();
         List<ConnectPoint> ports = new ArrayList<>();
 
         ArrayNode portArray = (ArrayNode) json.path(PORTS);
@@ -61,6 +63,6 @@
             ports.add(context.codec(ConnectPoint.class).decode((ObjectNode) o, context));
         }
 
-        return new FabricVlan(VlanId.vlanId(vlan), ports);
+        return new FabricVlan(VlanId.vlanId(vlan), ports, iptv);
     }
 }
diff --git a/apps/cordfabric/src/main/java/org/onosproject/cordfabric/cli/FabricAddCommand.java b/apps/cordfabric/src/main/java/org/onosproject/cordfabric/cli/FabricAddCommand.java
index cfa26be..e8cc641 100644
--- a/apps/cordfabric/src/main/java/org/onosproject/cordfabric/cli/FabricAddCommand.java
+++ b/apps/cordfabric/src/main/java/org/onosproject/cordfabric/cli/FabricAddCommand.java
@@ -59,6 +59,6 @@
             ports.add(ConnectPoint.deviceConnectPoint(portString));
         }
 
-        service.addVlan(new FabricVlan(vlan, ports));
+        service.addVlan(new FabricVlan(vlan, ports, false));
     }
 }
diff --git a/apps/xos-integration/src/main/java/org/onosproject/xosintegration/OnosXOSIntegrationManager.java b/apps/xos-integration/src/main/java/org/onosproject/xosintegration/OnosXOSIntegrationManager.java
index c9f7502..8ff1186 100644
--- a/apps/xos-integration/src/main/java/org/onosproject/xosintegration/OnosXOSIntegrationManager.java
+++ b/apps/xos-integration/src/main/java/org/onosproject/xosintegration/OnosXOSIntegrationManager.java
@@ -415,8 +415,16 @@
         //        + FABRIC_VCPE_CONNECT_POINT.toString() + "\"}";
         //json += "]}";
 
+        long vlan = portToVlan.get(fromPoint.port().toLong());
+
+
         JsonObject node = new JsonObject();
-        node.add("vlan", portToVlan.get(fromPoint.port().toLong()));
+        node.add("vlan", vlan);
+        if (vlan == 201) {
+            node.add("iptv", true);
+        } else {
+            node.add("iptv", false);
+        }
         JsonArray array = new JsonArray();
         JsonObject cp1 = new JsonObject();
         JsonObject cp2 = new JsonObject();
diff --git a/drivers/src/main/java/org/onosproject/driver/pipeline/OLTPipeline.java b/drivers/src/main/java/org/onosproject/driver/pipeline/OLTPipeline.java
index 79d2b0a..3b0195c 100644
--- a/drivers/src/main/java/org/onosproject/driver/pipeline/OLTPipeline.java
+++ b/drivers/src/main/java/org/onosproject/driver/pipeline/OLTPipeline.java
@@ -16,15 +16,12 @@
 package org.onosproject.driver.pipeline;
 
 import org.onlab.osgi.ServiceDirectory;
-import org.onlab.packet.Ethernet;
-import org.onosproject.core.ApplicationId;
 import org.onosproject.net.DeviceId;
 import org.onosproject.net.PortNumber;
 import org.onosproject.net.behaviour.Pipeliner;
 import org.onosproject.net.behaviour.PipelinerContext;
 import org.onosproject.net.driver.AbstractHandlerBehaviour;
 import org.onosproject.net.flow.DefaultFlowRule;
-import org.onosproject.net.flow.DefaultTrafficSelector;
 import org.onosproject.net.flow.DefaultTrafficTreatment;
 import org.onosproject.net.flow.FlowRule;
 import org.onosproject.net.flow.FlowRuleOperations;
@@ -52,7 +49,6 @@
     private FlowRuleService flowRuleService;
     private DeviceId deviceId;
 
-    private boolean done = false;
 
     @Override
     public void init(DeviceId deviceId, PipelinerContext context) {
@@ -63,34 +59,7 @@
 
     }
 
-    private boolean installIGMPRule(ApplicationId appId, boolean done) {
-        if (done) {
-            return done;
-        }
-        TrafficSelector selector = DefaultTrafficSelector.builder()
-                .matchInPort(PortNumber.portNumber(1))
-                .matchEthType(Ethernet.TYPE_IPV4)
-                .matchIPProtocol((byte) 2).build();
 
-        TrafficTreatment treatment = DefaultTrafficTreatment.builder()
-                .punt().build();
-
-        FlowRule rule = DefaultFlowRule.builder()
-                .forDevice(deviceId)
-                .fromApp(appId)
-                .withTreatment(treatment)
-                .withSelector(selector)
-                .makePermanent()
-                .withPriority(0)
-                .build();
-
-        FlowRuleOperations.Builder flowBuilder = FlowRuleOperations.builder();
-
-        flowRuleService.apply(flowBuilder.add(rule).build());
-
-        return true;
-
-    }
 
     @Override
     public void filter(FilteringObjective filter) {
@@ -99,7 +68,6 @@
 
     @Override
     public void forward(ForwardingObjective fwd) {
-        done = installIGMPRule(fwd.appId(), done);
         FlowRuleOperations.Builder flowBuilder = FlowRuleOperations.builder();
 
         if (fwd.flag() != ForwardingObjective.Flag.VERSATILE) {