Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 1 | """ |
| 2 | Copyright 2016 Open Networking Foundation (ONF) |
| 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 |
| 11 | (at your option) any later version. |
| 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 | """ |
| 21 | |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 22 | "**** Scripted by Antony Silvester ****** " |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 23 | import json |
| 24 | from urllib import addbase |
| 25 | import os |
| 26 | |
| 27 | |
| 28 | import requests |
| 29 | from requests.auth import HTTPBasicAuth |
| 30 | |
| 31 | |
| 32 | class BgpLs: |
| 33 | |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 34 | def __init__( self ): |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 35 | self.localAs = 100 |
| 36 | self.maxSession = 20 |
| 37 | self.lsCapability = True |
| 38 | self.holdTime = 180 |
| 39 | self.largeAsCapability = False |
| 40 | self.flowSpecCapability = 'IPV4' |
| 41 | self.flowSpecRpdCapability = False |
| 42 | self.remoteAs = 100 |
| 43 | self.peerHoldTime = 120 |
| 44 | self.connectMode = 'active' |
| 45 | self.bgpPeer = [] |
| 46 | self.routerId = '' |
| 47 | self.peerIp = '' |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 48 | |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 49 | def ipValue( self, localip, remoteip ): |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 50 | self.routerId = localip |
| 51 | self.peerIp = remoteip |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 52 | return self.routerId, self.peerIp |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 53 | |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 54 | def DictoJson( self ): |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 55 | Dicdata = {} |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 56 | org_bgp = [] |
| 57 | org_bgp.append( { 'peerIp': self.peerIp, 'remoteAs': self.remoteAs, |
| 58 | 'peerHoldTime': self.peerHoldTime, 'connectMode': self.connectMode } ) |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 59 | if self.routerId != '': |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 60 | Dicdata[ 'routerId' ] = self.routerId |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 61 | if self.localAs != '': |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 62 | Dicdata[ 'localAs' ] = self.localAs |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 63 | if self.maxSession != '': |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 64 | Dicdata[ 'maxSession' ] = self.maxSession |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 65 | if self.lsCapability != '': |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 66 | Dicdata[ 'lsCapability' ] = self.lsCapability |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 67 | if self.holdTime != '': |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 68 | Dicdata[ 'holdTime' ] = self.holdTime |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 69 | if self.largeAsCapability != '': |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 70 | Dicdata[ 'largeAsCapability' ] = self.largeAsCapability |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 71 | if self.flowSpecCapability != '': |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 72 | Dicdata[ 'flowSpecCapability' ] = self.flowSpecCapability |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 73 | if self.flowSpecRpdCapability != '': |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 74 | Dicdata[ 'flowSpecRpdCapability' ] = self.flowSpecRpdCapability |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 75 | if self.bgpPeer != '': |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 76 | Dicdata[ 'bgpPeer' ] = org_bgp |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 77 | |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 78 | Dicdata = { 'bgpapp': Dicdata } |
| 79 | Dicdata = { 'org.onosproject.provider.bgp.cfg': Dicdata } |
| 80 | Dicdata = { 'apps': Dicdata } |
| 81 | return json.dumps( Dicdata, indent=4 ) |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 82 | |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 83 | def Comments( self ): |
| 84 | print( "**********************************************************************************\n" ) |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 85 | |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 86 | def Constants( self ): |
| 87 | self.Ne_id_1 = '1111.1111.0011' |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 88 | self.Ne_id_2 = '2222.2222.0022' |
| 89 | self.Ne_id_3 = '3333.3333.0033' |
| 90 | self.Ne_id_4 = '4444.4444.0044' |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 91 | listnum = [ self.Ne_id_1, self.Ne_id_2, self.Ne_id_3, self.Ne_id_4, ] |
| 92 | var = [ self.peerIp ] |
| 93 | return var, listnum |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 94 | |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 95 | def apps( self ): |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 96 | self.app_bgp = 'org.onosproject.bgp' |
| 97 | self.app_bgpflow = 'org.onosproject.bgpflow' |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 98 | self.list1 = [ self.app_bgp, self.app_bgpflow ] |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 99 | return self.list1 |
AntonySilvester | 0265238 | 2016-07-13 16:44:45 +0530 | [diff] [blame] | 100 | |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 101 | def checkLinks( self, linksResp ): |
Jon Hall | 64b1757 | 2017-06-06 09:39:19 -0700 | [diff] [blame] | 102 | # Declaring the links values |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 103 | links = { 'link1_src': "1650.5555.0055", 'link1_dst': "1660.6666.0066", |
| 104 | 'link2_src': "1630.3333.0033", 'link2_dst': "1620.2222.0022", |
| 105 | 'link3_src': "1660.6666.0066", 'link3_dst': "1650.5555.0055", |
| 106 | 'link4_src': "1630.3333.0033", 'link4_dst': "1650.5555.0055", |
| 107 | 'link5_src': "1640.4444.0044", 'link5_dst': "1610.1111.0011", |
| 108 | 'link6_src': "1650.5555.0055", 'link4_dst': "1630.3333.0033", |
| 109 | 'link7_src': "1620.2222.0022", 'link4_dst': "1630.3333.0033", |
| 110 | 'link8_src': "1620.2222.0022", 'link4_dst': "1610.1111.0011", |
| 111 | 'link9_src': "1630.3333.0033", 'link4_dst': "1640.4444.0044", |
| 112 | 'link10_src': "1650.5555.0055", 'link4_dst': "1640.4444.0044", |
| 113 | 'link11_src': "1610.1111.0011", 'link4_dst': "1640.4444.0044", |
| 114 | 'link12_src': "1640.4444.0044", 'link4_dst': "1620.2222.0022", |
| 115 | 'link13_src': "1660.6666.0066", 'link4_dst': "1630.3333.0033", |
| 116 | 'link14_src': "1640.4444.0044", 'link4_dst': "1660.6666.0066", |
| 117 | 'link15_src': "1640.4444.0044", 'link4_dst': "1630.3333.0033", |
| 118 | 'link16_src': "1610.1111.0011", 'link4_dst': "1630.3333.0033", |
| 119 | 'link17_src': "1630.3333.0033", 'link4_dst': "1610.1111.0011", |
| 120 | 'link18_src': "1610.1111.0011", 'link4_dst': "1620.2222.0022", |
| 121 | 'link19_src': "1620.2222.0022", 'link4_dst': "1640.4444.0044", |
| 122 | 'link20_src': "1630.3333.0033", 'link4_dst': "1660.6666.0066", |
| 123 | 'link21_src': "1640.4444.0044", 'link4_dst': "1650.5555.0055", |
| 124 | 'link22_src': "1660.6666.0066", 'link4_dst': "1640.4444.0044" |
| 125 | } |
AntonySilvester | 0265238 | 2016-07-13 16:44:45 +0530 | [diff] [blame] | 126 | |
Jon Hall | 64b1757 | 2017-06-06 09:39:19 -0700 | [diff] [blame] | 127 | # Comparing the Links |
Devin Lim | 3d60b44 | 2017-08-03 17:59:56 -0700 | [diff] [blame^] | 128 | if len( linksResp ) != 22: |
| 129 | return False |
Jon Hall | 46fdea1 | 2017-05-24 15:48:57 -0700 | [diff] [blame] | 130 | for x in xrange( 22 ): |
| 131 | link_src_info = linksResp[ x ][ 'src' ][ 'device' ] |
| 132 | link_dst_info = linksResp[ x ][ 'dst' ][ 'device' ] |
| 133 | link_src_split = link_src_info.split( "=" ) |
| 134 | link_src = link_src_split[ 4 ] |
| 135 | link_dst_split = link_dst_info.split( "=" ) |
| 136 | link_dst = link_dst_split[ 4 ] |
| 137 | y = x + 1 |
| 138 | link_src_ref = links[ 'link' + str( y ) + '_src' ] |
| 139 | link_dst_ref = links[ 'link' + str( y ) + '_dst' ] |
| 140 | if ( link_src == link_src_ref ) and ( link_dst == ( link_dst_ref ) and |
| 141 | linksResp[ x ][ 'type' ] == 'DIRECT' and linksResp[ x ][ 'state' ] == |
| 142 | 'ACTIVE' ): |
AntonySilvester | 0265238 | 2016-07-13 16:44:45 +0530 | [diff] [blame] | 143 | return True |
| 144 | else: |
| 145 | return False |