blob: fb51097e3b0aa3d5bcf3e4c30070788e5f01446b [file] [log] [blame]
Matteo Scandoloeb0d11c2017-08-08 13:05:26 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
Scott Baker31acc652016-06-23 15:47:56 -070017#!/usr/bin/python
18import fnmatch
19import logging
20
21class sflow_sub_record:
22 def __init__(self,scheme,app_id,app_ip,app_port,subscription_info,sub_info_filter):
23 logging.debug("* Updating subscription_info ")
24 self.scheme = scheme
25 self.app_id = app_id
26 self.ipaddress = app_ip
27 self.portno = app_port
28 self.subscription_info = subscription_info
29 self.sub_info_filter = sub_info_filter
30
31sflow_sub_database=[]
32def add_sflow_sub_record(record):
33 logging.info("* inside %s",add_sflow_sub_record.__name__)
34 if not sflow_sub_database:
35 logging.debug("* -----------List is EMpty -------------")
36 sflow_sub_database.append(record)
37 logging.debug("* Subscription is sucessful")
38 return "Subscription is sucessful \n"
39 for x in sflow_sub_database:
40 if (record.ipaddress == x.ipaddress) and (record.portno == x.portno) :
41 logging.warning("* entry already exists\n")
42 return "entry already exists \n"
43 sflow_sub_database.append(record)
44 return "Subscription is sucessful \n"
45
46def delete_sflow_sub_record(ip,port):
47 logging.info("* inside %s",delete_sflow_sub_record.__name__)
48 Flag = False
49 for x in sflow_sub_database:
50 if (ip == x.ipaddress) and (port == x.portno) :
51 sflow_sub_database.remove(x)
52 Flag = True
53 logging.debug("* Un-Subscription is sucessful")
54 return "Un-Subscription is sucessful \n"
55 if not Flag :
56 err_str = "No subscription exists with target: udp://" + ip + ":" + str(port) + "\n"
57 logging.error(err_str)
58 raise Exception (err_str)
59
60def print_sflow_sub_records():
61 logging.info("* inside %s",print_sflow_sub_records.__name__)
62 for obj in sflow_sub_database:
63 logging.debug("* ------------------------------------------------")
64 logging.debug("* scheme:%s",obj.scheme)
65 logging.debug("* app_id:%s",obj.app_id)
66 logging.debug("* portno:%s",obj.portno )
67 logging.debug("* ipaddress:%s",obj.ipaddress)
68 logging.debug("* portno:%s",obj.portno)
69 logging.debug("* subscription_info:%s",obj.subscription_info)
70 logging.debug("* sub_info_filter:%s",obj.sub_info_filter)
71 logging.debug("* ------------------------------------------------")
72
73def get_sflow_sub_records(notif_subscription_info):
74 logging.info("* inside %s",get_sflow_sub_records.__name__)
75 sub_list=[]
76 for obj in sflow_sub_database:
77 if obj.subscription_info == notif_subscription_info:
78 sub_list.append(obj)
79 return sub_list