Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 1 | """ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 2 | Copyright 2016 Open Networking Foundation ( ONF ) |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 3 | |
| 4 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 5 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 6 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
| 7 | |
| 8 | TestON is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation, either version 2 of the License, or |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 11 | ( at your option ) any later version. |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 12 | |
| 13 | TestON is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 20 | """ |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 21 | "**** Scripted by Antony Silvester ****** " |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 22 | import json |
| 23 | from urllib import addbase |
| 24 | import os |
| 25 | |
| 26 | |
| 27 | import requests |
| 28 | from requests.auth import HTTPBasicAuth |
| 29 | |
| 30 | |
| 31 | class BgpLs: |
| 32 | |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 33 | def __init__( self ): |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 34 | self.localAs = 100 |
| 35 | self.maxSession = 20 |
| 36 | self.lsCapability = True |
| 37 | self.holdTime = 180 |
| 38 | self.largeAsCapability = False |
| 39 | self.flowSpecCapability = 'IPV4' |
| 40 | self.flowSpecRpdCapability = False |
| 41 | self.remoteAs = 100 |
| 42 | self.peerHoldTime = 120 |
| 43 | self.connectMode = 'active' |
| 44 | self.bgpPeer = [] |
| 45 | self.routerId = '' |
| 46 | self.peerIp = '' |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 47 | |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 48 | def ipValue( self, localip, remoteip ): |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 49 | self.routerId = localip |
| 50 | self.peerIp = remoteip |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 51 | return self.routerId, self.peerIp |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 52 | |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 53 | def DictoJson( self ): |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 54 | Dicdata = {} |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 55 | org_bgp = [] |
| 56 | org_bgp.append( { 'peerIp': self.peerIp, 'remoteAs': self.remoteAs, |
| 57 | 'peerHoldTime': self.peerHoldTime, 'connectMode': self.connectMode } ) |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 58 | if self.routerId != '': |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 59 | Dicdata[ 'routerId' ] = self.routerId |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 60 | if self.localAs != '': |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 61 | Dicdata[ 'localAs' ] = self.localAs |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 62 | if self.maxSession != '': |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 63 | Dicdata[ 'maxSession' ] = self.maxSession |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 64 | if self.lsCapability != '': |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 65 | Dicdata[ 'lsCapability' ] = self.lsCapability |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 66 | if self.holdTime != '': |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 67 | Dicdata[ 'holdTime' ] = self.holdTime |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 68 | if self.largeAsCapability != '': |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 69 | Dicdata[ 'largeAsCapability' ] = self.largeAsCapability |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 70 | if self.flowSpecCapability != '': |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 71 | Dicdata[ 'flowSpecCapability' ] = self.flowSpecCapability |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 72 | if self.flowSpecRpdCapability != '': |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 73 | Dicdata[ 'flowSpecRpdCapability' ] = self.flowSpecRpdCapability |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 74 | if self.bgpPeer != '': |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 75 | Dicdata[ 'bgpPeer' ] = org_bgp |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 76 | |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 77 | Dicdata = { 'bgpapp': Dicdata } |
| 78 | Dicdata = { 'org.onosproject.provider.bgp.cfg': Dicdata } |
| 79 | Dicdata = { 'apps': Dicdata } |
| 80 | return json.dumps( Dicdata, indent=4 ) |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 81 | |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 82 | def Comments( self ): |
| 83 | print( "**********************************************************************************\n" ) |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 84 | |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 85 | def Constants( self ): |
| 86 | self.Ne_id_1 = '1111.1111.0011' |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 87 | self.Ne_id_2 = '2222.2222.0022' |
| 88 | self.Ne_id_3 = '3333.3333.0033' |
| 89 | self.Ne_id_4 = '4444.4444.0044' |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 90 | listnum = [ self.Ne_id_1, self.Ne_id_2, self.Ne_id_3, self.Ne_id_4, ] |
| 91 | var = [ self.peerIp ] |
| 92 | return var, listnum |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 93 | |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 94 | def apps( self ): |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 95 | self.app_bgp = 'org.onosproject.bgp' |
| 96 | self.app_bgpflow = 'org.onosproject.bgpflow' |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 97 | self.list1 = [ self.app_bgp, self.app_bgpflow ] |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 98 | return self.list1 |
AntonySilvester | 0265238 | 2016-07-13 16:44:45 +0530 | [diff] [blame] | 99 | |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 100 | def checkLinks( self, linksResp ): |
Jon Hall | 64b1757 | 2017-06-06 09:39:19 -0700 | [diff] [blame] | 101 | # Declaring the links values |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 102 | links = { 'link1_src': "1650.5555.0055", 'link1_dst': "1660.6666.0066", |
| 103 | 'link2_src': "1630.3333.0033", 'link2_dst': "1620.2222.0022", |
| 104 | 'link3_src': "1660.6666.0066", 'link3_dst': "1650.5555.0055", |
| 105 | 'link4_src': "1630.3333.0033", 'link4_dst': "1650.5555.0055", |
| 106 | 'link5_src': "1640.4444.0044", 'link5_dst': "1610.1111.0011", |
| 107 | 'link6_src': "1650.5555.0055", 'link4_dst': "1630.3333.0033", |
| 108 | 'link7_src': "1620.2222.0022", 'link4_dst': "1630.3333.0033", |
| 109 | 'link8_src': "1620.2222.0022", 'link4_dst': "1610.1111.0011", |
| 110 | 'link9_src': "1630.3333.0033", 'link4_dst': "1640.4444.0044", |
| 111 | 'link10_src': "1650.5555.0055", 'link4_dst': "1640.4444.0044", |
| 112 | 'link11_src': "1610.1111.0011", 'link4_dst': "1640.4444.0044", |
| 113 | 'link12_src': "1640.4444.0044", 'link4_dst': "1620.2222.0022", |
| 114 | 'link13_src': "1660.6666.0066", 'link4_dst': "1630.3333.0033", |
| 115 | 'link14_src': "1640.4444.0044", 'link4_dst': "1660.6666.0066", |
| 116 | 'link15_src': "1640.4444.0044", 'link4_dst': "1630.3333.0033", |
| 117 | 'link16_src': "1610.1111.0011", 'link4_dst': "1630.3333.0033", |
| 118 | 'link17_src': "1630.3333.0033", 'link4_dst': "1610.1111.0011", |
| 119 | 'link18_src': "1610.1111.0011", 'link4_dst': "1620.2222.0022", |
| 120 | 'link19_src': "1620.2222.0022", 'link4_dst': "1640.4444.0044", |
| 121 | 'link20_src': "1630.3333.0033", 'link4_dst': "1660.6666.0066", |
| 122 | 'link21_src': "1640.4444.0044", 'link4_dst': "1650.5555.0055", |
| 123 | 'link22_src': "1660.6666.0066", 'link4_dst': "1640.4444.0044" |
| 124 | } |
AntonySilvester | 0265238 | 2016-07-13 16:44:45 +0530 | [diff] [blame] | 125 | |
Jon Hall | 64b1757 | 2017-06-06 09:39:19 -0700 | [diff] [blame] | 126 | # Comparing the Links |
Devin Lim | 3d60b44 | 2017-08-03 17:59:56 -0700 | [diff] [blame] | 127 | if len( linksResp ) != 22: |
| 128 | return False |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 129 | for x in xrange( 22 ): |
| 130 | link_src_info = linksResp[ x ][ 'src' ][ 'device' ] |
| 131 | link_dst_info = linksResp[ x ][ 'dst' ][ 'device' ] |
| 132 | link_src_split = link_src_info.split( "=" ) |
| 133 | link_src = link_src_split[ 4 ] |
| 134 | link_dst_split = link_dst_info.split( "=" ) |
| 135 | link_dst = link_dst_split[ 4 ] |
| 136 | y = x + 1 |
| 137 | link_src_ref = links[ 'link' + str( y ) + '_src' ] |
| 138 | link_dst_ref = links[ 'link' + str( y ) + '_dst' ] |
| 139 | if ( link_src == link_src_ref ) and ( link_dst == ( link_dst_ref ) and |
| 140 | linksResp[ x ][ 'type' ] == 'DIRECT' and linksResp[ x ][ 'state' ] == |
| 141 | 'ACTIVE' ): |
AntonySilvester | 0265238 | 2016-07-13 16:44:45 +0530 | [diff] [blame] | 142 | return True |
| 143 | else: |
| 144 | return False |