Пример #1
0
    def test_vdp_vlan_change_multiple_vnics_norem(self):
        """Testing the VDP VLAN change for multiple vnic's.

        This is for the case when there are multiple vNics for the same
        network and for one vNic a VDP VLAN of 0, is returned. So flow
        should not be deleted.
        """
        new_vdp_vlan = 0
        ovs_cb_data = {'port_uuid': self.port_uuid, 'net_uuid': self.net_uuid}
        with mock.patch('networking_cisco.apps.saf.common.'
                        'dfa_sys_lib.OVSBridge.add_flow') as (ovs_br_add), \
            mock.patch('networking_cisco.apps.saf.common.'
                       'dfa_sys_lib.OVSBridge.delete_flows') as (ovs_br_del):
            parent = mock.MagicMock()
            parent.attach_mock(ovs_br_del, 'delete_flows')
            parent.attach_mock(ovs_br_add, 'add_flow')
            self.ovs_vdp.local_vlan_map[self.net_uuid] = ovs_vdp.LocalVlan(
                self.lvid, self.segmentation_id)
            lvm = self.ovs_vdp.local_vlan_map[self.net_uuid]
            lvm.late_binding_vlan = self.exist_vdp_vlan
            lvm.set_port_uuid(self.port_uuid, self.exist_vdp_vlan, None)
            lvm.set_port_uuid(self.port_uuid_1, self.exist_vdp_vlan, None)
            self.ovs_vdp.vdp_vlan_change(ovs_cb_data, new_vdp_vlan, None)
        ovs_br_add.assert_not_called()
        ovs_br_del.assert_not_called()
Пример #2
0
    def test_flow_check_handler_both_flows_missing(self):
        """Testing the flow check handler for both bridges.

        Flow is missing for both bridges.
        """
        ext_flow = "NXST_FLOW reply (xid=0x4):"
        integ_flow = "NXST_FLOW reply (xid=0x4):"
        with mock.patch('networking_cisco.apps.saf.common.'
                        'dfa_sys_lib.OVSBridge.add_flow') as (ovs_br_add), \
            mock.patch.object(self.ovs_vdp.integ_br_obj, 'dump_flows_for',
                              return_value=integ_flow), \
            mock.patch.object(self.ovs_vdp.ext_br_obj, 'dump_flows_for',
                              return_value=ext_flow):
            parent = mock.MagicMock()
            parent.attach_mock(ovs_br_add, 'add_flow')
            self.ovs_vdp.local_vlan_map[self.net_uuid] = ovs_vdp.LocalVlan(
                self.lvid, self.segmentation_id)
            lvm = self.ovs_vdp.local_vlan_map[self.net_uuid]
            lvm.late_binding_vlan = self.exist_vdp_vlan
            lvm.lvid = self.lvid
            lvm.set_port_uuid(self.port_uuid, self.exist_vdp_vlan, None)
            self.ovs_vdp._flow_check_handler()
        expected_calls = [
            mock.call.add_flow(priority=4,
                               in_port=self.ovs_vdp.phy_peer_port_num,
                               dl_vlan=self.lvid,
                               actions="mod_vlan_vid:%s,normal" %
                               self.exist_vdp_vlan),
            mock.call.add_flow(priority=3,
                               in_port=self.ovs_vdp.int_peer_port_num,
                               dl_vlan=self.exist_vdp_vlan,
                               actions="mod_vlan_vid:%s,normal" % self.lvid)
        ]
        parent.assert_has_calls(expected_calls, any_order=False)
Пример #3
0
 def test_vdp_vlan_change_rem_add(self):
     """Testing the VDP VLAN change for a remove/add flow case. """
     new_vdp_vlan = 3006
     ovs_cb_data = {'port_uuid': self.port_uuid, 'net_uuid': self.net_uuid}
     with mock.patch('networking_cisco.apps.saf.common.'
                     'dfa_sys_lib.OVSBridge.delete_flows') as (ovs_br_del):
         parent = mock.MagicMock()
         parent.attach_mock(ovs_br_del, 'delete_flows')
         parent.attach_mock(self.ovs_br_add, 'add_flow')
         self.ovs_vdp.local_vlan_map[self.net_uuid] = ovs_vdp.LocalVlan(
             self.lvid, self.segmentation_id)
         lvm = self.ovs_vdp.local_vlan_map[self.net_uuid]
         lvm.late_binding_vlan = self.exist_vdp_vlan
         lvm.set_port_uuid(self.port_uuid, self.exist_vdp_vlan, None)
         self.ovs_vdp.vdp_vlan_change(ovs_cb_data, new_vdp_vlan, None)
     expected_calls = [
         mock.call.delete_flows(in_port=self.ovs_vdp.phy_peer_port_num,
                                dl_vlan=self.lvid),
         mock.call.delete_flows(in_port=self.ovs_vdp.int_peer_port_num,
                                dl_vlan=self.exist_vdp_vlan),
         mock.call.add_flow(priority=4,
                            in_port=self.ovs_vdp.phy_peer_port_num,
                            dl_vlan=self.lvid,
                            actions="mod_vlan_vid:%s,normal" %
                            new_vdp_vlan),
         mock.call.add_flow(priority=3,
                            in_port=self.ovs_vdp.int_peer_port_num,
                            dl_vlan=new_vdp_vlan,
                            actions="mod_vlan_vid:%s,normal" % self.lvid)
     ]
     parent.assert_has_calls(expected_calls, any_order=False)
Пример #4
0
    def test_vdp_port_event_down_mismatched_vlans(self):
        """Test the case for a vnic port down for a network with mismatch vlan.

        This is to test the case when there are more than one vNic for a
        network with mismatched VLAN's. Stale Flows should be removed and new
        flows should be added.
        """
        old_vdp_vlan = 3001
        status = 'down'
        with mock.patch('networking_cisco.apps.saf.common.'
                        'dfa_sys_lib.OVSBridge.delete_flows') as (del_flow), \
            mock.patch('networking_cisco.apps.saf.common.'
                       'dfa_sys_lib.OVSBridge.add_flow') as (add_flow), \
            mock.patch('networking_cisco.apps.saf.common.'
                       'dfa_sys_lib.OVSBridge.get_ofport_name',
                       return_value='test_port'), \
            mock.patch.object(self.ovs_vdp.lldpad_info,
                              'send_vdp_vnic_down') as vnic_down:
            self.ovs_vdp.local_vlan_map[self.net_uuid] = ovs_vdp.LocalVlan(
                self.lvid, self.segmentation_id)
            lvm = self.ovs_vdp.local_vlan_map[self.net_uuid]
            lvm.lvid = self.lvid
            lvm.set_port_uuid(self.port_uuid, self.exist_vdp_vlan, None)
            lvm.set_port_uuid(self.port_uuid_1, old_vdp_vlan, None)
            self.ovs_vdp.local_vlan_map[
                self.net_uuid].late_binding_vlan = self.exist_vdp_vlan
            parent = mock.MagicMock()
            parent.attach_mock(vnic_down, 'send_vdp_vnic_down')
            parent.attach_mock(del_flow, 'delete_flows')
            parent.attach_mock(add_flow, 'add_flow')
            self.ovs_vdp.send_vdp_port_event(self.port_uuid, self.mac,
                                             self.net_uuid,
                                             self.segmentation_id, status,
                                             self.oui)
        expected_calls = [
            mock.call.send_vdp_vnic_down(port_uuid=self.port_uuid,
                                         vsiid=self.port_uuid,
                                         gid=self.segmentation_id,
                                         mac=self.mac,
                                         vlan=self.exist_vdp_vlan,
                                         oui=self.oui),
            mock.call.delete_flows(in_port=self.ovs_vdp.phy_peer_port_num,
                                   dl_vlan=self.lvid),
            mock.call.delete_flows(in_port=self.ovs_vdp.int_peer_port_num,
                                   dl_vlan=self.exist_vdp_vlan),
            mock.call.add_flow(priority=4,
                               in_port=self.ovs_vdp.phy_peer_port_num,
                               dl_vlan=self.lvid,
                               actions="mod_vlan_vid:%s,normal" %
                               old_vdp_vlan),
            mock.call.add_flow(priority=3,
                               in_port=self.ovs_vdp.int_peer_port_num,
                               dl_vlan=old_vdp_vlan,
                               actions="mod_vlan_vid:%s,normal" % self.lvid)
        ]
        parent.assert_has_calls(expected_calls, any_order=False)
Пример #5
0
    def test_flow_check_handler_integ_flows_missing(self):
        """Testing the flow check handler for integ bridge.

        Flow is missing for integration bridge.
        """
        ext_flow = "NXST_FLOW reply (xid=0x4):\n" \
                   "cookie=0x0, duration=460654.804s, table=0, "\
                   "n_packets=3885, n_bytes=248632, idle_age=71, "\
                   "hard_age=65534, priority=3,in_port=1,dl_vlan=3005 "\
                   "actions=mod_vlan_vid:10,NORMAL\n" \
                   "cookie=0x9feb720beeec4ab9, duration=777857.315s, "\
                   "table=0, n_packets=32387, n_bytes=2186200, idle_age=4,"\
                   " hard_age=65534, priority=2,in_port=1 actions=drop"
        integ_flow = "NXST_FLOW reply (xid=0x4):"
        with mock.patch('networking_cisco.apps.saf.common.'
                        'dfa_sys_lib.OVSBridge.add_flow') as (ovs_br_add), \
            mock.patch.object(self.ovs_vdp.integ_br_obj, 'dump_flows_for',
                              return_value=integ_flow), \
            mock.patch.object(self.ovs_vdp.ext_br_obj, 'dump_flows_for',
                              return_value=ext_flow):
            parent = mock.MagicMock()
            parent.attach_mock(ovs_br_add, 'add_flow')
            self.ovs_vdp.local_vlan_map[self.net_uuid] = ovs_vdp.LocalVlan(
                self.lvid, self.segmentation_id)
            lvm = self.ovs_vdp.local_vlan_map[self.net_uuid]
            lvm.late_binding_vlan = self.exist_vdp_vlan
            lvm.lvid = self.lvid
            lvm.set_port_uuid(self.port_uuid, self.exist_vdp_vlan, None)
            self.ovs_vdp._flow_check_handler()
        expected_calls = [
            mock.call.add_flow(priority=4,
                               in_port=self.ovs_vdp.phy_peer_port_num,
                               dl_vlan=self.lvid,
                               actions="mod_vlan_vid:%s,normal" %
                               self.exist_vdp_vlan),
            mock.call.add_flow(priority=3,
                               in_port=self.ovs_vdp.int_peer_port_num,
                               dl_vlan=self.exist_vdp_vlan,
                               actions="mod_vlan_vid:%s,normal" % self.lvid)
        ]
        parent.assert_has_calls(expected_calls, any_order=False)
Пример #6
0
 def _test_vdp_port_event_down(self):
     '''Test the case for a vnic port down for a network '''
     port_uuid = '0000-1111-2222-3334'
     mac = '00:00:fa:11:22:34'
     net_uuid = '0000-aaaa-bbbb-cccc'
     segmentation_id = 10001
     status = 'down'
     oui = None
     with mock.patch('networking_cisco.apps.saf.common.'
                     'dfa_sys_lib.OVSBridge.delete_flows') as (del_flow), \
         mock.patch('networking_cisco.apps.saf.common.'
                    'dfa_sys_lib.OVSBridge.get_ofport_name',
                    return_value='test_port'), \
         mock.patch.object(self.ovs_vdp.lldpad_info,
                           'send_vdp_vnic_down') as vnic_down:
         self.ovs_vdp.local_vlan_map[net_uuid] = ovs_vdp.LocalVlan(
             10, (segmentation_id))
         lvm = self.ovs_vdp.local_vlan_map[net_uuid]
         lvm.lvid = 10
         lvm.port_uuid_list[port_uuid] = port_uuid
         self.ovs_vdp.local_vlan_map[net_uuid].late_binding_vlan = 500
         phy_port_num = 5
         int_peer_port_num = 6
         self.ovs_vdp.phy_peer_port_num = phy_port_num
         self.ovs_vdp.int_peer_port_num = int_peer_port_num
         parent = mock.MagicMock()
         parent.attach_mock(vnic_down, 'send_vdp_vnic_down')
         parent.attach_mock(del_flow, 'delete_flows')
         self.ovs_vdp.send_vdp_port_event(port_uuid, mac, net_uuid,
                                          segmentation_id, status, oui)
     expected_calls = [
         mock.call.send_vdp_vnic_down(port_uuid=port_uuid,
                                      vsiid=port_uuid,
                                      gid=segmentation_id,
                                      mac=mac,
                                      vlan=500,
                                      oui=oui),
         mock.call.delete_flows(in_port=phy_port_num, dl_vlan=10),
         mock.call.delete_flows(in_port=int_peer_port_num, dl_vlan=500)
     ]
     parent.assert_has_calls(expected_calls, any_order=False)
Пример #7
0
    def test_vdp_port_event_down_valid_vlan(self):
        """Test the case for a vnic port down for a network.

        This is to test the case when there are more than one vNic for a
        network with a valid VLAN. Flows should not be removed.
        """
        status = 'down'
        with mock.patch('networking_cisco.apps.saf.common.'
                        'dfa_sys_lib.OVSBridge.delete_flows') as (del_flow), \
            mock.patch('networking_cisco.apps.saf.common.'
                       'dfa_sys_lib.OVSBridge.get_ofport_name',
                       return_value='test_port'), \
            mock.patch.object(self.ovs_vdp.lldpad_info,
                              'send_vdp_vnic_down') as vnic_down:
            self.ovs_vdp.local_vlan_map[self.net_uuid] = ovs_vdp.LocalVlan(
                self.lvid, self.segmentation_id)
            lvm = self.ovs_vdp.local_vlan_map[self.net_uuid]
            lvm.lvid = self.lvid
            lvm.set_port_uuid(self.port_uuid, self.exist_vdp_vlan, None)
            lvm.set_port_uuid(self.port_uuid_1, self.exist_vdp_vlan, None)
            self.ovs_vdp.local_vlan_map[
                self.net_uuid].late_binding_vlan = self.exist_vdp_vlan
            parent = mock.MagicMock()
            parent.attach_mock(vnic_down, 'send_vdp_vnic_down')
            parent.attach_mock(del_flow, 'delete_flows')
            self.ovs_vdp.send_vdp_port_event(self.port_uuid, self.mac,
                                             self.net_uuid,
                                             self.segmentation_id, status,
                                             self.oui)
        expected_calls = [
            mock.call.send_vdp_vnic_down(port_uuid=self.port_uuid,
                                         vsiid=self.port_uuid,
                                         gid=self.segmentation_id,
                                         mac=self.mac,
                                         vlan=self.exist_vdp_vlan,
                                         oui=self.oui)
        ]
        parent.assert_has_calls(expected_calls, any_order=False)
        del_flow.assert_not_called()
Пример #8
0
    def test_flow_check_handler_no_flows_missing(self):
        """Testing the flow check handler for both bridges.

        No flows are missing in both the bridges.
        """
        new_vdp_vlan = 3005
        ext_flow = "NXST_FLOW reply (xid=0x4):\n" \
                   "cookie=0x0, duration=460654.804s, table=0, "\
                   "n_packets=3885, n_bytes=248632, idle_age=71, "\
                   "hard_age=65534, priority=3,in_port=1,dl_vlan=10 "\
                   "actions=mod_vlan_vid:3005,NORMAL\n" \
                   "cookie=0x9feb720beeec4ab9, duration=777857.315s, "\
                   "table=0, n_packets=32387, n_bytes=2186200, idle_age=4,"\
                   " hard_age=65534, priority=2,in_port=1 actions=drop"
        integ_flow = "NXST_FLOW reply (xid=0x4):\n" \
                     "cookie=0x0, duration=460654.804s, table=0, "\
                     "n_packets=3885, n_bytes=248632, idle_age=71, "\
                     "hard_age=65534, priority=3,in_port=1,dl_vlan=3005 "\
                     "actions=mod_vlan_vid:10,NORMAL\n" \
                     "cookie=0x9feb720beeec4ab9, duration=777857.315s, "\
                     "table=0, n_packets=32387, n_bytes=2186200, idle_age=4,"\
                     " hard_age=65534, priority=2,in_port=1 actions=drop"
        with mock.patch('networking_cisco.apps.saf.common.'
                        'dfa_sys_lib.OVSBridge.add_flow') as (ovs_br_add), \
            mock.patch.object(self.ovs_vdp.integ_br_obj, 'dump_flows_for',
                              return_value=integ_flow), \
            mock.patch.object(self.ovs_vdp.ext_br_obj, 'dump_flows_for',
                              return_value=ext_flow):
            parent = mock.MagicMock()
            parent.attach_mock(ovs_br_add, 'add_flow')
            self.ovs_vdp.local_vlan_map[self.net_uuid] = ovs_vdp.LocalVlan(
                self.lvid, self.segmentation_id)
            lvm = self.ovs_vdp.local_vlan_map[self.net_uuid]
            lvm.late_binding_vlan = new_vdp_vlan
            lvm.lvid = self.lvid
            lvm.set_port_uuid(self.port_uuid, new_vdp_vlan, None)
            self.ovs_vdp._flow_check_handler()
        ovs_br_add.assert_not_called()