Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 1 | "**** Scripted by Antony Silvester ****** " |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 2 | import json |
| 3 | from urllib import addbase |
| 4 | import os |
| 5 | |
| 6 | |
| 7 | import requests |
| 8 | from requests.auth import HTTPBasicAuth |
| 9 | |
| 10 | |
| 11 | class BgpLs: |
| 12 | |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 13 | def __init__( self ): |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 14 | 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 Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 29 | def ipValue( self, localip, remoteip ): |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 30 | self.routerId = localip |
| 31 | self.peerIp = remoteip |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 32 | return self.routerId, self.peerIp |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 33 | |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 34 | def DictoJson( self ): |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 35 | Dicdata = {} |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 36 | org_bgp = [] |
| 37 | org_bgp.append( { 'peerIp': self.peerIp, 'remoteAs': self.remoteAs, |
| 38 | 'peerHoldTime': self.peerHoldTime, 'connectMode': self.connectMode } ) |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 39 | if self.routerId != '': |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 40 | Dicdata[ 'routerId' ] = self.routerId |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 41 | if self.localAs != '': |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 42 | Dicdata[ 'localAs' ] = self.localAs |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 43 | if self.maxSession != '': |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 44 | Dicdata[ 'maxSession' ] = self.maxSession |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 45 | if self.lsCapability != '': |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 46 | Dicdata[ 'lsCapability' ] = self.lsCapability |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 47 | if self.holdTime != '': |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 48 | Dicdata[ 'holdTime' ] = self.holdTime |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 49 | if self.largeAsCapability != '': |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 50 | Dicdata[ 'largeAsCapability' ] = self.largeAsCapability |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 51 | if self.flowSpecCapability != '': |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 52 | Dicdata[ 'flowSpecCapability' ] = self.flowSpecCapability |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 53 | if self.flowSpecRpdCapability != '': |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 54 | Dicdata[ 'flowSpecRpdCapability' ] = self.flowSpecRpdCapability |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 55 | if self.bgpPeer != '': |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 56 | Dicdata[ 'bgpPeer' ] = org_bgp |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 57 | |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 58 | Dicdata = { 'bgpapp': Dicdata } |
| 59 | Dicdata = { 'org.onosproject.provider.bgp.cfg': Dicdata } |
| 60 | Dicdata = { 'apps': Dicdata } |
| 61 | return json.dumps( Dicdata, indent=4 ) |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 62 | |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 63 | def Comments( self ): |
| 64 | print( "**********************************************************************************\n" ) |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 65 | |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 66 | def Constants( self ): |
| 67 | self.Ne_id_1 = '1111.1111.0011' |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 68 | self.Ne_id_2 = '2222.2222.0022' |
| 69 | self.Ne_id_3 = '3333.3333.0033' |
| 70 | self.Ne_id_4 = '4444.4444.0044' |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 71 | 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 |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 74 | |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 75 | def apps( self ): |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 76 | self.app_bgp = 'org.onosproject.bgp' |
| 77 | self.app_bgpflow = 'org.onosproject.bgpflow' |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 78 | self.list1 = [ self.app_bgp, self.app_bgpflow ] |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 79 | return self.list1 |
AntonySilvester | 0265238 | 2016-07-13 16:44:45 +0530 | [diff] [blame] | 80 | |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 81 | def checkLinks( self, linksResp ): |
AntonySilvester | 0265238 | 2016-07-13 16:44:45 +0530 | [diff] [blame] | 82 | #Declaring the links values |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 83 | 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 | } |
AntonySilvester | 0265238 | 2016-07-13 16:44:45 +0530 | [diff] [blame] | 106 | |
| 107 | #Comparing the Links |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 108 | 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' ): |
AntonySilvester | 0265238 | 2016-07-13 16:44:45 +0530 | [diff] [blame] | 121 | return True |
| 122 | else: |
| 123 | return False |