コード例 #1
0
 def publish_event(self, pub_set, op):
     for pub_item in pub_set:
         vlan_id = self.get_vlan_id(pub_item.br_name)
         if vlan_id is None:
             log_err('Failed to get VLAN ID for bridge %s' %
                     pub_item.br_name)
             continue
         if isinstance(pub_item, McastGroupInfo):
             evt_data = {
                 'vlan-id': vlan_id,
                 ('group', '0', 'interface'): pub_item.if_name,
                 ('group', '0', 'address'): pub_item.grp_ip_str
             }
             is_igmp = pub_item.is_igmp
         elif isinstance(pub_item, McastRouterInfo):
             evt_data = {
                 'vlan-id': vlan_id,
                 'mrouter-interface': [pub_item.if_name]
             }
             is_igmp = True
         evt_obj = events.MCast_CpsEvents()
         if is_igmp:
             evt_obj.publish_igmp_events(evt_data, op)
         else:
             evt_obj.publish_mld_events(evt_data, op)
コード例 #2
0
def _handle_mcast_snoop_configs_fs(data, vlan_name, igmp_events, op):
    ret = True
    for k in _ip_link_cmd_params:
        for path in _ip_link_cmd_params[k]['obj_path']:
          if path in data:
              if op == "delete":
                  log_err("Unsupported operation for mcast snoop configs")
                  return False

              # In case of igmp/mld disable on a vlan, Clear cache
              if k == 'mcast_snooping' and data[path] == 0:
                  try:
                      polling_thread.flush_cache(vlan_name)
                  except Exception as e:
                      logging.exception(e)
                      return False

              if k == 'mcast_last_member_interval' or k == 'mcast_query_interval': val = str( data[path] * 100 )
              else: val = str(data[path])

              # Update Multicast Snooping on a VLAN
              ret = ret and (_update_file_system(_get_path_per_vlan_configs(vlan_name, _ip_link_cmd_params[k]['file_name']), val))

              # Publish CPS Events if required
              event_data = {}
              if _ip_link_cmd_params[k]['publish_events']:
                  ev_key = path.split("/")[-1]
                  if _keys['vlan_id_key']['igmp'] in data:  id = data[_keys['vlan_id_key']['igmp']]
                  elif _keys['vlan_id_key']['mld'] in data:  id = data[_keys['vlan_id_key']['mld']]
                  event_data = {'vlan-id': str(id), ev_key :str( data[path])}

              if ret and event_data:
                 obj = events.MCast_CpsEvents()
                 # Since snoop config variables like mcast status are common for both IPv4 and IPv6, publishing the corresponding events on both igmp and mld state objects
                 obj.publish_igmp_events(event_data, op)
                 obj.publish_mld_events(event_data, op)
                 log_debug("Publishing CPS Event: %s" %(str(event_data)))

              # In case of igmp/mld enable, set the max groups as 16k and hash_elasticity as 8
              if k == 'mcast_snooping' and data[path] == 1:
                  ret = ret and polling_thread.hashmax_cfg_to_queue(vlan_name, max_grps)
                  ret = ret and (_update_file_system(_get_path_per_vlan_configs(vlan_name, "hash_elasticity"),
                                                            def_mcast_hash_elasticity))

              # In case of multicast query interval, kernel doesn't update multicast membership interval file and multicast_querier_interval file, hence updating it manually
              if k == 'mcast_query_interval':
                  mcast_query_response_interval = _read_file_system(_get_path_per_vlan_configs(vlan_name, "multicast_query_response_interval"))
                  if not mcast_query_response_interval: return False

                  #As per RFC The Group Membership Interval value MUST be ((the Robustness Variable) times (the Query Interval)) plus (one Query Response Interval)
                  val = ((data[path]*2)+(int(mcast_query_response_interval)/100))*100
                  ret = ret and (_update_file_system(_get_path_per_vlan_configs(vlan_name, "multicast_membership_interval"), val))

                  #As per RFC The Other Querier Present Interval value MUST be ((the Robustness Variable) times (the Query Interval)) plus (one half of one Query Response Interval)
                  val = ((data[path]*2)+((int(mcast_query_response_interval)/100)/2))*100
                  ret = ret and (_update_file_system(_get_path_per_vlan_configs(vlan_name, "multicast_querier_interval"), val))
    return ret
コード例 #3
0
def _parse_mcast_snoop_updates_and_publish(data, vlan_info, vlan_id,
                                           igmp_events, op):

    #Parse status, mrouter and route update and publish.
    vlan_name = vlan_info['cps/key_data']['if/interfaces/interface/name']
    try:
        for k in _snoop_obj_info:
            for path in _snoop_obj_info[k]['obj_path']:
                if path in data and _snoop_obj_info[k]['publish_events']:
                    # Publish CPS Events if required
                    event_data = {}
                    mcast_utils.log_info(
                        '%s %s %s for VLAN %d' %
                        ('IGMP' if igmp_events else 'MLD',
                         _snoop_obj_info[k]['event_string'], op, vlan_id))
                    if (k == 'static_l2_mcast_grp_key'):
                        if (_parse_snoop_routes(vlan_id, vlan_info, op,
                                                igmp_events, data[path],
                                                event_data)) is False:
                            return False
                    elif (k == 'static_mrouter_key'):
                        if (_parse_snoop_mrouter_ports(vlan_id, vlan_info, op,
                                                       data[path],
                                                       event_data)) is False:
                            return False
                    elif (k == 'mcast_snooping'):
                        if (_parse_snoop_status(igmp_events, vlan_id,
                                                data[path], vlan_name,
                                                event_data)) is False:
                            return False

                    obj = events.MCast_CpsEvents()
                    if event_data:
                        if igmp_events:
                            obj.publish_igmp_events(event_data, op)
                        else:
                            obj.publish_mld_events(event_data, op)

                        mcast_utils.log_info(
                            "Publishing %s %s %s event" %
                            (('IGMP ' if igmp_events else 'MLD '),
                             _snoop_obj_info[k]['event_string'], op))
                        mcast_utils.log_debug("Publish event data: %s" %
                                              (str(event_data)))

    except Exception as e:
        mcast_utils.log_err('Exception: %s' % e)

    return True
コード例 #4
0
def _handle_mcast_snoop_configs(cmd, data, vlan_name, igmp_events, op,
                                snoop_cfg_flags):
    if op == "delete":
        log_err("Unsupported operation for mcast snoop configs")
        return False
    res = []
    for k in _ip_link_cmd_params:
        for path in _ip_link_cmd_params[k]['obj_path']:
            if path in data:
                snoop_cfg_flags[0] = True

                cmd = [iplink_cmd, 'link', 'set', vlan_name, 'type', 'bridge']

                if k == 'mcast_last_member_interval' or k == 'mcast_query_interval':
                    val = str(data[path] * 100)
                else:
                    val = str(data[path])

                cmd.extend((k, val))

                event_data = {}

                if _ip_link_cmd_params[k]['publish_events']:
                    ev_key = path.split("/")[-1]
                    if _keys['vlan_id_key']['igmp'] in data:
                        id = data[_keys['vlan_id_key']['igmp']]
                    elif _keys['vlan_id_key']['mld'] in data:
                        id = data[_keys['vlan_id_key']['mld']]
                    event_data = {'vlan-id': str(id), ev_key: str(data[path])}

                if run_command(cmd, res) == 0:
                    if event_data:
                        # Publish CPS events
                        obj = events.MCast_CpsEvents()
                        if igmp_events: obj.publish_igmp_events(event_data, op)
                        else: obj.publish_mld_events(event_data, op)
                        log_debug("Publishing CPS Event: %s" %
                                  (str(event_data)))

                    return True
                else:
                    return False

    return True