AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 1 | """**** Scripted by Antony Silvester ****** """ |
| 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 | |
| 13 | def __init__(self): |
| 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 | |
| 29 | def ipValue(self,localip,remoteip): |
| 30 | self.routerId = localip |
| 31 | self.peerIp = remoteip |
| 32 | return self.routerId , self.peerIp |
| 33 | |
| 34 | def DictoJson(self): |
| 35 | Dicdata = {} |
| 36 | org_bgp =[] |
| 37 | org_bgp.append({'peerIp': self.peerIp , 'remoteAs':self.remoteAs, |
| 38 | 'peerHoldTime':self.peerHoldTime , 'connectMode':self.connectMode }) |
| 39 | if self.routerId != '': |
| 40 | Dicdata['routerId'] = self.routerId |
| 41 | if self.localAs != '': |
| 42 | Dicdata['localAs'] = self.localAs |
| 43 | if self.maxSession != '': |
| 44 | Dicdata['maxSession'] = self.maxSession |
| 45 | if self.lsCapability != '': |
| 46 | Dicdata['lsCapability'] = self.lsCapability |
| 47 | if self.holdTime != '': |
| 48 | Dicdata['holdTime'] = self.holdTime |
| 49 | if self.largeAsCapability != '': |
| 50 | Dicdata['largeAsCapability'] = self.largeAsCapability |
| 51 | if self.flowSpecCapability != '': |
| 52 | Dicdata['flowSpecCapability'] = self.flowSpecCapability |
| 53 | if self.flowSpecRpdCapability != '': |
| 54 | Dicdata['flowSpecRpdCapability'] = self.flowSpecRpdCapability |
| 55 | if self.bgpPeer != '': |
| 56 | Dicdata['bgpPeer'] = org_bgp |
| 57 | |
| 58 | Dicdata = {'bgpapp':Dicdata} |
| 59 | Dicdata = {'org.onosproject.provider.bgp.cfg':Dicdata} |
| 60 | Dicdata = {'apps':Dicdata} |
| 61 | return json.dumps(Dicdata,indent=4) |
| 62 | |
| 63 | |
| 64 | def Comments(self): |
| 65 | print("**********************************************************************************\n") |
| 66 | |
| 67 | def Constants(self): |
| 68 | self.Ne_id_1 = '1111.1111.0011' |
| 69 | self.Ne_id_2 = '2222.2222.0022' |
| 70 | self.Ne_id_3 = '3333.3333.0033' |
| 71 | self.Ne_id_4 = '4444.4444.0044' |
| 72 | listnum = [self.Ne_id_1,self.Ne_id_2,self.Ne_id_3,self.Ne_id_4,] |
| 73 | var = [self.peerIp] |
| 74 | return var,listnum |
| 75 | |
| 76 | def apps(self): |
| 77 | self.app_bgp = 'org.onosproject.bgp' |
| 78 | self.app_bgpflow = 'org.onosproject.bgpflow' |
| 79 | self.list1 = [self.app_bgp,self.app_bgpflow] |
| 80 | return self.list1 |
AntonySilvester | 0265238 | 2016-07-13 16:44:45 +0530 | [diff] [blame] | 81 | |
| 82 | def checkLinks(self,linksResp): |
| 83 | #Declaring the links values |
| 84 | links = {'link1_src' : "1650.5555.0055", 'link1_dst' : "1660.6666.0066", |
| 85 | 'link2_src' : "1630.3333.0033", 'link2_dst' : "1620.2222.0022", |
| 86 | 'link3_src' : "1660.6666.0066", 'link3_dst' : "1650.5555.0055", |
| 87 | 'link4_src' : "1630.3333.0033", 'link4_dst' : "1650.5555.0055", |
| 88 | 'link5_src' : "1640.4444.0044", 'link5_dst' : "1610.1111.0011", |
| 89 | 'link6_src' : "1650.5555.0055", 'link4_dst' : "1630.3333.0033", |
| 90 | 'link7_src' : "1620.2222.0022", 'link4_dst' : "1630.3333.0033", |
| 91 | 'link8_src' : "1620.2222.0022", 'link4_dst' : "1610.1111.0011", |
| 92 | 'link9_src' : "1630.3333.0033", 'link4_dst' : "1640.4444.0044", |
| 93 | 'link10_src' : "1650.5555.0055", 'link4_dst' : "1640.4444.0044", |
| 94 | 'link11_src' : "1610.1111.0011", 'link4_dst' : "1640.4444.0044", |
| 95 | 'link12_src' : "1640.4444.0044", 'link4_dst' : "1620.2222.0022", |
| 96 | 'link13_src' : "1660.6666.0066", 'link4_dst' : "1630.3333.0033", |
| 97 | 'link14_src' : "1640.4444.0044", 'link4_dst' : "1660.6666.0066", |
| 98 | 'link15_src' : "1640.4444.0044", 'link4_dst' : "1630.3333.0033", |
| 99 | 'link16_src' : "1610.1111.0011", 'link4_dst' : "1630.3333.0033", |
| 100 | 'link17_src' : "1630.3333.0033", 'link4_dst' : "1610.1111.0011", |
| 101 | 'link18_src' : "1610.1111.0011", 'link4_dst' : "1620.2222.0022", |
| 102 | 'link19_src' : "1620.2222.0022", 'link4_dst' : "1640.4444.0044", |
| 103 | 'link20_src' : "1630.3333.0033", 'link4_dst' : "1660.6666.0066", |
| 104 | 'link21_src' : "1640.4444.0044", 'link4_dst' : "1650.5555.0055", |
| 105 | 'link22_src' : "1660.6666.0066", 'link4_dst' : "1640.4444.0044" |
| 106 | } |
| 107 | |
| 108 | #Comparing the Links |
| 109 | for x in xrange(22): |
| 110 | link_src_info = linksResp[x]['src']['device'] |
| 111 | link_dst_info = linksResp[x]['dst']['device'] |
| 112 | link_src_split = link_src_info.split("=") |
| 113 | link_src = link_src_split[4] |
| 114 | link_dst_split = link_dst_info.split("=") |
| 115 | link_dst = link_dst_split[4] |
| 116 | y = x+1 |
| 117 | link_src_ref = links['link'+str(y)+'_src'] |
| 118 | link_dst_ref = links['link'+str(y)+'_dst'] |
| 119 | if (link_src == link_src_ref) and (link_dst == (link_dst_ref) and \ |
| 120 | linksResp[x]['type'] == 'DIRECT' and linksResp[x]['state'] == \ |
| 121 | 'ACTIVE'): |
| 122 | return True |
| 123 | else: |
| 124 | return False |