def topo_monitor():
    
    time_interval=0.2
    print '==========================================================='
    print ctime(),'Loading the Redundancy rules...'
    print '==========================================================='
    reds=redundancy_Builder()
    numoflb=len(reds)
    print ctime()+str(numoflb)+'Redundancy rules Loaded!'
    print '==========================================================='
    print ctime(),'Topology Monitor started'
    data_orig=get_topology()
    data_old=get_topology()
    numoflinks=len(data_orig['edgeProperties'])
    print str(numoflinks),'links detected'
    print '========================Log================================'
    for link_index_old in range(numoflinks):
        s1=data_orig['edgeProperties'][link_index_old]['edge']['tailNodeConnector']['node']['id'] #switch ID
        p1=data_orig['edgeProperties'][link_index_old]['edge']['tailNodeConnector']['id'] #Port ID
        s2=data_orig['edgeProperties'][link_index_old]['edge']['headNodeConnector']['node']['id'] #switch ID
        p2=data_orig['edgeProperties'][link_index_old]['edge']['headNodeConnector']['id'] #Port ID
        print' Switch ',s1,' port ',p1,' connected to ',' Switch ',s2,' port ',p2
    
    while 1:
        time.sleep(time_interval)
        data_new=get_topology()
        result_topo_deleted={'headNodeConnector':[],'hn port':[],'tailNodeConnector':[],'tn port':[]}
        result_topo_added={'headNodeConnector':[],'hn port':[],'tailNodeConnector':[],'tn port':[]}
        result_switch=check_topo(data_orig,data_old,data_new,result_topo_deleted,reds)
        data_old=data_new
    def __init__(self, root):

        self.root = root
        self.frame_traffic = LabelFrame(self.root,
                                        text="Traffic Visualization",
                                        font=30)
        self.frame_traffic.pack()

        self.refresh_index = 1

        self.switch_image = PhotoImage(file="switch.gif")

        self.height = 600
        self.width = 800
        self.cv = Canvas(self.frame_traffic,
                         bg='white',
                         height=self.height,
                         width=self.width)

        self.switches = []
        self.links = []

        self.data_old = get_all_ports_statics()

        #add switch

        self.data = get_topology()
        self.num_of_links = len(self.data['edgeProperties'])
        for index in range(self.num_of_links):
            switch_id_1 = self.data['edgeProperties'][index]['edge'][
                'headNodeConnector']['node']['id']

            if check_new_switch(self.switches, switch_id_1) == 0:
                new_switch_1 = switch(switch_id_1, self.cv, self.switch_image,
                                      random.randint(30, 370),
                                      random.randint(30, 370))
                self.switches.append(new_switch_1)

            switch_id_2 = self.data['edgeProperties'][index]['edge'][
                'tailNodeConnector']['node']['id']
            if check_new_switch(self.switches, switch_id_2) == 0:
                new_switch_2 = switch(switch_id_2, self.cv, self.switch_image,
                                      random.randint(30, 370),
                                      random.randint(30, 370))
                self.switches.append(new_switch_2)

            if check_new_link(self.links, switch_id_1, switch_id_2) == 0:
                print 'creat link'
                port_1 = self.data['edgeProperties'][index]['edge'][
                    'headNodeConnector']['id']
                port_2 = self.data['edgeProperties'][index]['edge'][
                    'tailNodeConnector']['id']
                new_link = link_helper(
                    switch_finder(self.switches, switch_id_1),
                    switch_finder(self.switches, switch_id_2), self.cv, port_1,
                    port_2)
                self.links.append(new_link)

        self.cv.pack()
Example #3
0
def topo_monitor():

    time_interval = 0.2
    print '**********************************************************'
    print '*                                                        *'
    print '*     Topolodgy Detection and Redundancy Service         *'
    print '*                                                        *'
    print '**********************************************************'

    reds = redundancy_Builder()
    numoflb = len(reds)
    red_status = {}
    for red in reds:
        red_status[red['redundancy name']] = 'inactive'

    print '[Service Info]' + ctime()
    print str(numoflb) + ' Redundancy rules Loaded!'

    data_orig = get_topology()
    data_old = get_topology()
    numoflinks = len(data_orig['edgeProperties'])

    print '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'
    print '[Service Info]' + ctime()
    print '>Here are the ' + str(numoflinks), ' links detected in the ODL'

    for link_index_old in range(numoflinks):
        s1 = data_orig['edgeProperties'][link_index_old]['edge'][
            'tailNodeConnector']['node']['id']  #switch ID
        p1 = data_orig['edgeProperties'][link_index_old]['edge'][
            'tailNodeConnector']['id']  #Port ID
        s2 = data_orig['edgeProperties'][link_index_old]['edge'][
            'headNodeConnector']['node']['id']  #switch ID
        p2 = data_orig['edgeProperties'][link_index_old]['edge'][
            'headNodeConnector']['id']  #Port ID
        print '[Link' + str(link_index_old + 1) + '] ' + get_switch_name(
            s1), ' port ', p1, ' connected to ', get_switch_name(
                s2), ' port ', p2

    while 1:
        time.sleep(time_interval)
        data_new = get_topology()
        result_topo_deleted = {}
        red_status = check_topo(data_orig, data_old, data_new,
                                result_topo_deleted, reds, red_status)
        data_old = data_new
Example #4
0
def topo_monitor():

    time_interval = 0.2
    print '==========================================================='
    print ctime(), 'Loading the Redundancy rules...'
    print '==========================================================='
    reds = redundancy_Builder()
    numoflb = len(reds)
    print ctime() + str(numoflb) + 'Redundancy rules Loaded!'
    print '==========================================================='
    print ctime(), 'Topology Monitor started'
    data_orig = get_topology()
    data_old = get_topology()
    numoflinks = len(data_orig['edgeProperties'])
    print str(numoflinks), 'links detected'
    print '========================Log================================'
    for link_index_old in range(numoflinks):
        s1 = data_orig['edgeProperties'][link_index_old]['edge'][
            'tailNodeConnector']['node']['id']  #switch ID
        p1 = data_orig['edgeProperties'][link_index_old]['edge'][
            'tailNodeConnector']['id']  #Port ID
        s2 = data_orig['edgeProperties'][link_index_old]['edge'][
            'headNodeConnector']['node']['id']  #switch ID
        p2 = data_orig['edgeProperties'][link_index_old]['edge'][
            'headNodeConnector']['id']  #Port ID
        print ' Switch ', s1, ' port ', p1, ' connected to ', ' Switch ', s2, ' port ', p2

    while 1:
        time.sleep(time_interval)
        data_new = get_topology()
        result_topo_deleted = {
            'headNodeConnector': [],
            'hn port': [],
            'tailNodeConnector': [],
            'tn port': []
        }
        result_topo_added = {
            'headNodeConnector': [],
            'hn port': [],
            'tailNodeConnector': [],
            'tn port': []
        }
        result_switch = check_topo(data_orig, data_old, data_new,
                                   result_topo_deleted, reds)
        data_old = data_new
    def restart(self):

        for item in self.switches:

            self.cv.delete(item.name)
        for item in self.links:
            self.cv.delete(item.name)

        self.switches = []
        self.links = []

        self.data_old = get_all_ports_statics()

        #add switch

        self.data = get_topology()
        self.num_of_links = len(self.data['edgeProperties'])
        for index in range(self.num_of_links):
            switch_id_1 = self.data['edgeProperties'][index]['edge'][
                'headNodeConnector']['node']['id']

            if check_new_switch(self.switches, switch_id_1) == 0:
                new_switch_1 = switch(switch_id_1, self.cv, self.switch_image,
                                      random.randint(30, 370),
                                      random.randint(30, 370))
                self.switches.append(new_switch_1)

            switch_id_2 = self.data['edgeProperties'][index]['edge'][
                'tailNodeConnector']['node']['id']
            if check_new_switch(self.switches, switch_id_2) == 0:
                new_switch_2 = switch(switch_id_2, self.cv, self.switch_image,
                                      random.randint(30, 370),
                                      random.randint(30, 370))
                self.switches.append(new_switch_2)

            if check_new_link(self.links, switch_id_1, switch_id_2) == 0:
                print 'creat link'
                port_1 = self.data['edgeProperties'][index]['edge'][
                    'headNodeConnector']['id']
                port_2 = self.data['edgeProperties'][index]['edge'][
                    'tailNodeConnector']['id']
                new_link = link_helper(
                    switch_finder(self.switches, switch_id_1),
                    switch_finder(self.switches, switch_id_2), self.cv, port_1,
                    port_2)
                self.links.append(new_link)
        for switch_t in self.switches:
            switch_t.draw()
        self.cv.delete('time')
        self.time = self.cv.create_text((550, 480),
                                        text='Last updated: ' + ctime(),
                                        anchor=W,
                                        tags='time')
        self.ini = 1
Example #6
0
def topo_monitor():
    
    time_interval=0.2
    print '**********************************************************'
    print '*                                                        *'        
    print '*     Topolodgy Detection and Redundancy Service         *'
    print '*                                                        *'
    print '**********************************************************'
    
    reds=redundancy_Builder()
    numoflb=len(reds)
    red_status={}
    for red in reds:
        red_status[red['redundancy name']]='inactive'


    print '[Service Info]'+ctime()   
    print str(numoflb)+' Redundancy rules Loaded!'

    data_orig=get_topology()
    data_old=get_topology()
    numoflinks=len(data_orig['edgeProperties'])

    print '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'
    print '[Service Info]'+ctime()  
    print '>Here are the '+str(numoflinks),' links detected in the ODL'

    for link_index_old in range(numoflinks):
        s1=data_orig['edgeProperties'][link_index_old]['edge']['tailNodeConnector']['node']['id'] #switch ID
        p1=data_orig['edgeProperties'][link_index_old]['edge']['tailNodeConnector']['id'] #Port ID
        s2=data_orig['edgeProperties'][link_index_old]['edge']['headNodeConnector']['node']['id'] #switch ID
        p2=data_orig['edgeProperties'][link_index_old]['edge']['headNodeConnector']['id'] #Port ID
        print '[Link'+str(link_index_old+1)+'] '+get_switch_name(s1),' port ',p1,' connected to ',get_switch_name(s2),' port ',p2
    
    while 1:
        time.sleep(time_interval)
        data_new=get_topology()
        result_topo_deleted={}
        red_status=check_topo(data_orig,data_old,data_new,result_topo_deleted,reds,red_status)
        data_old=data_new
    def refresh(self, event):
        print 'refresh started'
        if self.ini == 0:
            self.data_old = get_all_ports_statics()
            self.restart()
            self.ini = 1

        self.time_interval = 1
        self.mode = 'all'
        #time.sleep(self.time_interval)
        self.data_new = get_all_ports_statics()
        self.result_switch = {'Added Port': [], 'Deleted Port': []}
        self.result_rate = []
        #Refresh data rate
        self.rates = check_ports_rate_spg(self.data_old, self.data_new,
                                          self.result_switch,
                                          self.time_interval, self.mode,
                                          self.result_rate)
        self.time = self.cv.create_text((550, 480),
                                        text='Last updated: ' + ctime(),
                                        anchor=W,
                                        tags='time')

        for link in self.links:
            head_rate = self.get_rate(self.rates, link.head, link.head_port)
            tail_rate = self.get_rate(self.rates, link.head, link.head_port)
            if head_rate['TX_rate'] != 'none':
                if tail_rate['RX_rate'] != 'none':
                    link.colorrate(
                        min(head_rate['TX_rate'], tail_rate['RX_rate']))
        #Refresh link

        self.result = check_topo_spg(self.data, self.data, get_topology())
        for link in self.result['Remove link']:
            result_t = self.find_link(link)
            if result_t != 'none':
                result_t.broken()

        for link in self.result['Add link']:
            result_t = self.find_link(link)
            if result_t != 'none':
                result_t.recovery()

        self.data_old = self.data_new
        print 'relodad'
        self.cv.delete('time')
        self.time = self.cv.create_text((550, 480),
                                        text='Last updated: ' + ctime(),
                                        anchor=W,
                                        tags='time')

        thread.start_new_thread(self.auto_triger, ())
        def __init__(self):


                self.root = Tk()
                self.frame_traffic = LabelFrame(self.root,text="Traffic Visualization",font=30)
                self.frame_traffic.pack()

                
                self.switch_image= PhotoImage(file = "switch.gif")
                self.start_image=PhotoImage(file = "start.gif")
                self.height=500
                self.width=500
                self.cv = Canvas(self.frame_traffic,bg = 'white',height=self.height,width=self.width)
                                
                self.switches=[]
                self.links=[]

                self.data_old=get_all_ports_statics()

                #start button
                self.start=self.cv.create_image(64,0,anchor=NE,image=self.start_image,tags='start')
                self.cv.tag_bind('start',' <Button-1>',self.refresh)
                self.refresh()
                
                #add switch
                                             
                self.data=get_topology()
                self.num_of_links=len(self.data['edgeProperties'])
                for index in range(self.num_of_links):
                        switch_id_1=self.data['edgeProperties'][index]['edge']['headNodeConnector']['node']['id']

                        if check_new_switch(self.switches,switch_id_1)==0:
                                new_switch_1=switch(switch_id_1,self.cv,self.switch_image,random.randint(30,370),random.randint(30,370))
                                self.switches.append(new_switch_1)

                        switch_id_2=self.data['edgeProperties'][index]['edge']['tailNodeConnector']['node']['id']
                        if check_new_switch(self.switches,switch_id_2)==0:
                                new_switch_2=switch(switch_id_2,self.cv,self.switch_image,random.randint(30,370),random.randint(30,370))
                                self.switches.append(new_switch_2)

                        if check_new_link(self.links,switch_id_1,switch_id_2)==0:
                                print 'creat link'
                                port_1=self.data['edgeProperties'][index]['edge']['headNodeConnector']['id']
                                port_2=self.data['edgeProperties'][index]['edge']['tailNodeConnector']['id']
                                new_link=link_helper(switch_finder(self.switches,switch_id_1),switch_finder(self.switches,switch_id_2),self.cv,port_1,port_2)
                                self.links.append(new_link)
                
                                  
                self.cv.pack()
                self.root.mainloop()