blob: 14f150061e5286479c2d14873b6143da32d2f00d [file] [log] [blame]
Jon Hall46fdea12017-05-24 15:48:57 -07001"**** Scripted by Antony Silvester ****** "
AntonySilvestera1080f22016-04-26 13:05:57 +05302import json
3from urllib import addbase
4import os
5
6
7import requests
8from requests.auth import HTTPBasicAuth
9
10
11class BgpLs:
12
Jon Hall46fdea12017-05-24 15:48:57 -070013 def __init__( self ):
AntonySilvestera1080f22016-04-26 13:05:57 +053014 self.localAs = 100
15 self.maxSession = 20
16 self.lsCapability = True
17 self.holdTime = 180
18 self.largeAsCapability = False
19 self.flowSpecCapability = 'IPV4'
20 self.flowSpecRpdCapability = False
21 self.remoteAs = 100
22 self.peerHoldTime = 120
23 self.connectMode = 'active'
24 self.bgpPeer = []
25 self.routerId = ''
26 self.peerIp = ''
27 #self.org_bgp = []
28
Jon Hall46fdea12017-05-24 15:48:57 -070029 def ipValue( self, localip, remoteip ):
AntonySilvestera1080f22016-04-26 13:05:57 +053030 self.routerId = localip
31 self.peerIp = remoteip
Jon Hall46fdea12017-05-24 15:48:57 -070032 return self.routerId, self.peerIp
AntonySilvestera1080f22016-04-26 13:05:57 +053033
Jon Hall46fdea12017-05-24 15:48:57 -070034 def DictoJson( self ):
AntonySilvestera1080f22016-04-26 13:05:57 +053035 Dicdata = {}
Jon Hall46fdea12017-05-24 15:48:57 -070036 org_bgp = []
37 org_bgp.append( { 'peerIp': self.peerIp, 'remoteAs': self.remoteAs,
38 'peerHoldTime': self.peerHoldTime, 'connectMode': self.connectMode } )
AntonySilvestera1080f22016-04-26 13:05:57 +053039 if self.routerId != '':
Jon Hall46fdea12017-05-24 15:48:57 -070040 Dicdata[ 'routerId' ] = self.routerId
AntonySilvestera1080f22016-04-26 13:05:57 +053041 if self.localAs != '':
Jon Hall46fdea12017-05-24 15:48:57 -070042 Dicdata[ 'localAs' ] = self.localAs
AntonySilvestera1080f22016-04-26 13:05:57 +053043 if self.maxSession != '':
Jon Hall46fdea12017-05-24 15:48:57 -070044 Dicdata[ 'maxSession' ] = self.maxSession
AntonySilvestera1080f22016-04-26 13:05:57 +053045 if self.lsCapability != '':
Jon Hall46fdea12017-05-24 15:48:57 -070046 Dicdata[ 'lsCapability' ] = self.lsCapability
AntonySilvestera1080f22016-04-26 13:05:57 +053047 if self.holdTime != '':
Jon Hall46fdea12017-05-24 15:48:57 -070048 Dicdata[ 'holdTime' ] = self.holdTime
AntonySilvestera1080f22016-04-26 13:05:57 +053049 if self.largeAsCapability != '':
Jon Hall46fdea12017-05-24 15:48:57 -070050 Dicdata[ 'largeAsCapability' ] = self.largeAsCapability
AntonySilvestera1080f22016-04-26 13:05:57 +053051 if self.flowSpecCapability != '':
Jon Hall46fdea12017-05-24 15:48:57 -070052 Dicdata[ 'flowSpecCapability' ] = self.flowSpecCapability
AntonySilvestera1080f22016-04-26 13:05:57 +053053 if self.flowSpecRpdCapability != '':
Jon Hall46fdea12017-05-24 15:48:57 -070054 Dicdata[ 'flowSpecRpdCapability' ] = self.flowSpecRpdCapability
AntonySilvestera1080f22016-04-26 13:05:57 +053055 if self.bgpPeer != '':
Jon Hall46fdea12017-05-24 15:48:57 -070056 Dicdata[ 'bgpPeer' ] = org_bgp
AntonySilvestera1080f22016-04-26 13:05:57 +053057
Jon Hall46fdea12017-05-24 15:48:57 -070058 Dicdata = { 'bgpapp': Dicdata }
59 Dicdata = { 'org.onosproject.provider.bgp.cfg': Dicdata }
60 Dicdata = { 'apps': Dicdata }
61 return json.dumps( Dicdata, indent=4 )
AntonySilvestera1080f22016-04-26 13:05:57 +053062
Jon Hall46fdea12017-05-24 15:48:57 -070063 def Comments( self ):
64 print( "**********************************************************************************\n" )
AntonySilvestera1080f22016-04-26 13:05:57 +053065
Jon Hall46fdea12017-05-24 15:48:57 -070066 def Constants( self ):
67 self.Ne_id_1 = '1111.1111.0011'
AntonySilvestera1080f22016-04-26 13:05:57 +053068 self.Ne_id_2 = '2222.2222.0022'
69 self.Ne_id_3 = '3333.3333.0033'
70 self.Ne_id_4 = '4444.4444.0044'
Jon Hall46fdea12017-05-24 15:48:57 -070071 listnum = [ self.Ne_id_1, self.Ne_id_2, self.Ne_id_3, self.Ne_id_4, ]
72 var = [ self.peerIp ]
73 return var, listnum
AntonySilvestera1080f22016-04-26 13:05:57 +053074
Jon Hall46fdea12017-05-24 15:48:57 -070075 def apps( self ):
AntonySilvestera1080f22016-04-26 13:05:57 +053076 self.app_bgp = 'org.onosproject.bgp'
77 self.app_bgpflow = 'org.onosproject.bgpflow'
Jon Hall46fdea12017-05-24 15:48:57 -070078 self.list1 = [ self.app_bgp, self.app_bgpflow ]
AntonySilvestera1080f22016-04-26 13:05:57 +053079 return self.list1
AntonySilvester02652382016-07-13 16:44:45 +053080
Jon Hall46fdea12017-05-24 15:48:57 -070081 def checkLinks( self, linksResp ):
AntonySilvester02652382016-07-13 16:44:45 +053082 #Declaring the links values
Jon Hall46fdea12017-05-24 15:48:57 -070083 links = { 'link1_src': "1650.5555.0055", 'link1_dst': "1660.6666.0066",
84 'link2_src': "1630.3333.0033", 'link2_dst': "1620.2222.0022",
85 'link3_src': "1660.6666.0066", 'link3_dst': "1650.5555.0055",
86 'link4_src': "1630.3333.0033", 'link4_dst': "1650.5555.0055",
87 'link5_src': "1640.4444.0044", 'link5_dst': "1610.1111.0011",
88 'link6_src': "1650.5555.0055", 'link4_dst': "1630.3333.0033",
89 'link7_src': "1620.2222.0022", 'link4_dst': "1630.3333.0033",
90 'link8_src': "1620.2222.0022", 'link4_dst': "1610.1111.0011",
91 'link9_src': "1630.3333.0033", 'link4_dst': "1640.4444.0044",
92 'link10_src': "1650.5555.0055", 'link4_dst': "1640.4444.0044",
93 'link11_src': "1610.1111.0011", 'link4_dst': "1640.4444.0044",
94 'link12_src': "1640.4444.0044", 'link4_dst': "1620.2222.0022",
95 'link13_src': "1660.6666.0066", 'link4_dst': "1630.3333.0033",
96 'link14_src': "1640.4444.0044", 'link4_dst': "1660.6666.0066",
97 'link15_src': "1640.4444.0044", 'link4_dst': "1630.3333.0033",
98 'link16_src': "1610.1111.0011", 'link4_dst': "1630.3333.0033",
99 'link17_src': "1630.3333.0033", 'link4_dst': "1610.1111.0011",
100 'link18_src': "1610.1111.0011", 'link4_dst': "1620.2222.0022",
101 'link19_src': "1620.2222.0022", 'link4_dst': "1640.4444.0044",
102 'link20_src': "1630.3333.0033", 'link4_dst': "1660.6666.0066",
103 'link21_src': "1640.4444.0044", 'link4_dst': "1650.5555.0055",
104 'link22_src': "1660.6666.0066", 'link4_dst': "1640.4444.0044"
105 }
AntonySilvester02652382016-07-13 16:44:45 +0530106
107 #Comparing the Links
Jon Hall46fdea12017-05-24 15:48:57 -0700108 for x in xrange( 22 ):
109 link_src_info = linksResp[ x ][ 'src' ][ 'device' ]
110 link_dst_info = linksResp[ x ][ 'dst' ][ 'device' ]
111 link_src_split = link_src_info.split( "=" )
112 link_src = link_src_split[ 4 ]
113 link_dst_split = link_dst_info.split( "=" )
114 link_dst = link_dst_split[ 4 ]
115 y = x + 1
116 link_src_ref = links[ 'link' + str( y ) + '_src' ]
117 link_dst_ref = links[ 'link' + str( y ) + '_dst' ]
118 if ( link_src == link_src_ref ) and ( link_dst == ( link_dst_ref ) and
119 linksResp[ x ][ 'type' ] == 'DIRECT' and linksResp[ x ][ 'state' ] ==
120 'ACTIVE' ):
AntonySilvester02652382016-07-13 16:44:45 +0530121 return True
122 else:
123 return False