Tibit DHCP and Multicast MAC tests.

Change-Id: I46c2e6613de537e6f434d2658f34c24bc0ea7504
diff --git a/cli/main.py b/cli/main.py
index 12a157f..8f7c064 100755
--- a/cli/main.py
+++ b/cli/main.py
@@ -621,6 +621,35 @@
 
     complete_install_all_sample_flows = VolthaCli.complete_logical_device
 
+    def do_install_dhcp_flows(self, line):
+        """
+        Install all dhcp flows that are representative of the virtualized access
+        scenario in a PON network.
+        """
+        logical_device_id = line or self.default_logical_device_id
+
+        # gather NNI and UNI port IDs
+        nni_port_no, uni_port_no, c_vid = \
+            self.get_logical_ports(logical_device_id)
+
+        # construct and push flow rules
+        stub = voltha_pb2.VolthaLocalServiceStub(self.get_channel())
+
+        # Controller-bound flows
+        stub.UpdateLogicalDeviceFlowTable(FlowTableUpdate(
+            id=logical_device_id,
+            flow_mod=mk_simple_flow_mod(
+                priority=1000,
+                match_fields=[eth_type(0x800), ip_proto(17), udp_dst(67)],
+                actions=[output(ofp.OFPP_CONTROLLER)]
+            )
+        ))
+
+
+        self.poutput('success')
+
+    complete_install_dhcp_flows = VolthaCli.complete_logical_device
+
     def do_delete_all_flows(self, line):
         """
         Remove all flows and flow groups from given logical device
diff --git a/voltha/adapters/tibit_olt/tibit_olt.py b/voltha/adapters/tibit_olt/tibit_olt.py
index 7f549c1..41dfda4 100644
--- a/voltha/adapters/tibit_olt/tibit_olt.py
+++ b/voltha/adapters/tibit_olt/tibit_olt.py
@@ -427,6 +427,8 @@
                  flows=flows, groups=groups)
         assert len(groups.items) == 0, "Cannot yet deal with groups"
 
+        ONU_VID_208=0xd0
+
         Clause = {v: k for k, v in ClauseSubtypeEnum.iteritems()}
         Operator = {v: k for k, v in RuleOperatorEnum.iteritems()}
 
@@ -454,12 +456,10 @@
                     elif field.type == IP_PROTO:
                         _proto = field.ip_proto
                         log.info('#### field.type == IP_PROTO ####')
-                        pass  # construct ip_proto based condition here
 
                     elif field.type == IN_PORT:
                         _port = field.port
                         log.info('#### field.type == IN_PORT ####', port=_port)
-                        pass  # construct in_port based condition here
 
                     elif field.type == VLAN_VID:
                         _vlan_vid = field.vlan_vid & 0xfff
@@ -468,24 +468,19 @@
                                                                      operator=Operator['=='], match=_vlan_vid)
                         if (_vlan_vid != 140):
                             dn_req /= PortIngressRuleClauseMatchLength02(fieldcode=Clause['C-VLAN Tag'], fieldinstance=1,
-                                                                         operator=Operator['=='], match=0x00f1)
+                                                                         operator=Operator['=='], match=ONU_VID_208)
 
                     elif field.type == VLAN_PCP:
                         _vlan_pcp = field.vlan_pcp
                         log.info('#### field.type == VLAN_PCP ####', pcp=_vlan_pcp)
-                        pass  # construct VLAN PCP based filter condition here
 
                     elif field.type == UDP_DST:
                         _udp_dst = field.udp_dst
                         log.info('#### field.type == UDP_DST ####')
-                        pass  # construct UDP SDT based filter here
 
                     elif field.type == IPV4_DST:
-                        _udp_dst = field.ipv4_dst
+                        _ipv4_dst = field.ipv4_dst
                         log.info('#### field.type == IPV4_DST ####')
-                        import pdb
-                        pdb.set_trace()
-                        pass  # construct UDP SDT based filter here
 
                     else:
                         raise NotImplementedError('field.type={}'.format(
@@ -496,12 +491,14 @@
                     if action.type == OUTPUT:
                         log.info('#### action.type == OUTPUT ####')
                         dn_req /= PortIngressRuleResultForward()
-                        dn_req /= PortIngressRuleResultOLTQueue(unicastvssn="TBIT", unicastlink=0xe2222900)
+                        serial = ONU_VID_208 - 200
+                        link = (0xe222 << 16) | (serial << 8)
+                        dn_req /= PortIngressRuleResultOLTQueue(unicastvssn="TBIT",
+                                                                unicastlink=link)
 
                     elif action.type == POP_VLAN:
                         log.info('#### action.type == POP_VLAN ####')
                         dn_req /= PortIngressRuleResultDelete(fieldcode=Clause['S-VLAN Tag'])
-                        pass  # construct vlan pop command here
 
                     elif action.type == PUSH_VLAN:
                         log.info('#### action.type == PUSH_VLAN ####')
diff --git a/voltha/adapters/tibit_onu/tibit_onu.py b/voltha/adapters/tibit_onu/tibit_onu.py
index 424a1f9..1a50406 100644
--- a/voltha/adapters/tibit_onu/tibit_onu.py
+++ b/voltha/adapters/tibit_onu/tibit_onu.py
@@ -59,6 +59,7 @@
 
 from voltha.extensions.eoam.EOAM import EOAMPayload, CablelabsOUI
 from voltha.extensions.eoam.EOAM import DPoEOpcode_GetRequest, DPoEOpcode_SetRequest
+from voltha.extensions.eoam.EOAM import mcastIp2McastMac
 
 @implementer(IAdapterInterface)
 class TibitOnuAdapter(object):
@@ -213,7 +214,7 @@
             precedence = 255 - min(flow.priority / 256, 255)
 
             if in_port == 2:
-                log.info('#### Downstream Rule ####')
+                log.info('#### Upstream Rule ####')
                 dn_req = EOAMPayload(body=CablelabsOUI() /
                                      DPoEOpcode_SetRequest())
 
@@ -226,12 +227,10 @@
                     elif field.type == IP_PROTO:
                         _proto = field.ip_proto
                         log.info('#### field.type == IP_PROTO ####')
-                        pass  # construct ip_proto based condition here
 
                     elif field.type == IN_PORT:
                         _port = field.port
                         log.info('#### field.type == IN_PORT ####', port=_port)
-                        pass  # construct in_port based condition here
 
                     elif field.type == VLAN_VID:
                         _vlan_vid = field.vlan_vid & 0xfff
@@ -240,19 +239,14 @@
                     elif field.type == VLAN_PCP:
                         _vlan_pcp = field.vlan_pcp
                         log.info('#### field.type == VLAN_PCP ####', pcp=_vlan_pcp)
-                        pass  # construct VLAN PCP based filter condition here
 
                     elif field.type == UDP_DST:
                         _udp_dst = field.udp_dst
                         log.info('#### field.type == UDP_DST ####')
-                        pass  # construct UDP SDT based filter here
 
                     elif field.type == IPV4_DST:
                         _ipv4_dst = field.ipv4_dst
-                        import pdb
-                        pdb.set_trace()
                         log.info('#### field.type == IPV4_DST ####')
-                        pass
 
                     else:
                         log.info('#### field.type == NOT IMPLEMENTED!! ####')
@@ -266,7 +260,6 @@
 
                     elif action.type == POP_VLAN:
                         log.info('#### action.type == POP_VLAN ####')
-                        pass  # construct vlan pop command here
 
                     elif action.type == PUSH_VLAN:
                         log.info('#### action.type == PUSH_VLAN ####')
@@ -288,14 +281,8 @@
                         log.error('UNSUPPORTED-ACTION-TYPE',
                                   action_type=action.type)
 
-                # send message
-                log.info('ONU-send-proxied-message')
-#                self.adapter_agent.send_proxied_message(device.proxy_address, dn_req)
-
-
             elif in_port == 1:
-                # Upstream rule
-                log.info('#### Upstream Rule ####')
+                log.info('#### Downstream Rule ####')
 
                 #### Loop through fields again...
 
@@ -314,7 +301,6 @@
                     elif field.type == IN_PORT:
                         _port = field.port
                         log.info('#### field.type == IN_PORT ####')
-                        pass  # construct in_port based condition here
 
                     elif field.type == VLAN_VID:
                         _vlan_vid = field.vlan_vid & 0xfff
@@ -323,12 +309,29 @@
                     elif field.type == VLAN_PCP:
                         _vlan_pcp = field.vlan_pcp
                         log.info('#### field.type == VLAN_PCP ####')
-                        pass  # construct VLAN PCP based filter condition here
 
                     elif field.type == UDP_DST:
                         _udp_dst = field.udp_dst
                         log.info('#### field.type == UDP_DST ####')
 
+                    elif field.type == IPV4_DST:
+                        _ipv4_dst = field.ipv4_dst
+                        log.info('#### field.type == IPV4_DST ####')
+                        a = int(hex(_ipv4_dst)[2:4], 16)
+                        b = int(hex(_ipv4_dst)[4:6], 16)
+                        c = int(hex(_ipv4_dst)[6:8], 16)
+                        d = int(hex(_ipv4_dst)[8:], 16)
+                        dn_req = EOAMPayload(body=CablelabsOUI() /
+                                          DPoEOpcode_SetRequest() /
+                                          AddStaticMacAddress(
+                                              mac=mcastIp2McastMac('%d.%d.%d.%d' % (a,b,c,d)))
+                                          )
+                        # send message
+                        log.info('ONU-send-proxied-message')
+                        self.adapter_agent.send_proxied_message(device.proxy_address,
+                                                                dn_req)
+
+
                     else:
                         raise NotImplementedError('field.type={}'.format(
                             field.type))
@@ -340,7 +343,6 @@
 
                     elif action.type == POP_VLAN:
                         log.info('#### action.type == POP_VLAN ####')
-                        pass  # construct vlan pop command here
 
                     elif action.type == PUSH_VLAN:
                         log.info('#### action.type == PUSH_VLAN ####')