1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
#!/bin/sh
# test script for vpn subscribing
L3VPN = 3
AUTH = 'admin:admin'
URLTENANT = 'http://127.0.0.1:8091/v1/tenant'
URLCPE = 'http://127.0.0.1:8091/v1/cpe'
URLSTATUS = 'http://127.0.0.1:18002/resmgr/v1/dev?dev_id='
URLINTERFACE = 'http://127.0.0.1:8091/v1/cpe/interface'
URLSERVICE = 'http://127.0.0.1:8091/v1/vpn'
tenantid = 'opnfv'
tenantname = 'opnfv'
esn1 = '21500102003GH5000971'
interface1 = 'GigabitEthernet0/0/3'
vlan1 = 3006
subnet1 = '172.168.2.0'
mask2 = 24
gateway1 = '10.10.2.2'
esn2 = '2102114469P0H3000011'
interface2 = '10GE6/0/16'
vlan2 = 3000
subnet2 = '172.168.1.0'
mask2 = 24
gateway2 = '10.10.1.2'
function createtenant {
result = curl -I -H 'Content-type:application/json' -X POST -d '{ "tenant_id": $1,
"tenant_name":$2, "cert_type": "A", "cert_num": "000000000000000000001"}' -u $AUTH $URLTENANT
echo 'tenant $1 is being created!'
return result
}
function enablecpe {
cpe_model = "4096"
if [ $3 -eq "IMG"]; then
cpe_model = "4098"
fi
if [ $3 -eq "UCPE"]; then
cpe_model = "4096"
fi
result = curl -I -H 'Content-type:application/json' -X POST -d ' { "cpe_vendor": "HUAWEI", "tenant_id": $2, "ctrler_id": "HW_AC_CAMPUS_CQ1", "access_type": 0, "cpe_model": $cpe_moel, "cpe_esn": $1 }' -u $URLCPE
echo 'cpe $1 is being activated!'
return result
}
function checkstatus {
URL = {$URLSTATUS}{$1}
result = curl -I -H "Content-type: application/json" -X GET -u $AUTH $URL
status = jq '.status' $result
return status
}
function cfglaninterface {
result = curl -I -H 'Content-type:application/json' -X POST -d '{ "cpe_esn": $1, "interfaces": [ { "if_name": $2, "if_vlan": $3, "if_ip":$4, "if_mask":"24"}] }' -u $URLINTERFACE
echo 'cpe $1 interface $2 vlan $3 is being configured!'
return result
}
function enablesite2site {
result = curl -I -H 'Content-type:application/json' -X POST -d '{
"tenant_id": $1,
"bandwidth": 51200,
"order_id": "20180116-16",
"operation": 1,
"order_name": "20180116-16",
"internet_cfg": null,
"vas_cfg": null,
"vpn_config": [
{
"tenant_id": $1,
"vpn_id": 1,
"vpn_type": $L3VPN,
"local_device": $2,
"dl_bw": 1000,
"ul_bw": 1000,
"route_policy": false,
"qos_grade": null,
"local_type": 0,
"local_access": {
"web_enable": 1,
"dhcp_server": 1,
"portvlan_list": [
{
"port": $3,
"vlan": $4
}
],
"subnet_list": [
{
"ipv4": $5,
"mask_bit": "24",
"gateway": "$6
}
]
},
"remote_device": $7,
"remote_type": 0,
"remote_access": {
"dhcp_server": 1,
"web_enable": 1,
"portvlan_list": [
{
"port": $8,
"vlan": $9
}
],
"subnet_list": [
{
"ipv4": $10,
"mask_bit": 24,
"gateway": $11
}
]
}
}
]
}' -u $URLSERVICE
echo 'site2site between cpe $2 and cpe $3 is being activated for tenant $1!'
return result
}
tenantresult = createtenant $tenantid $tenantname
if [ $tenantresult -eq 201 ]; then
echo 'tenant opnfv has been successfully created!'
ucperesult = enablecpe $esn1 $tenantid "UCPE"
if [ $ucperesult -eq 201 ]; then
echo 'cpe $esn1 has been successfully enabled!'
elif [ $cpe1result -eq 404 ]; then
echo 'tenant $tenantid not exits!'
elif [ $cpe1result -eq 409 ]; then
echo 'cpe $esn1 already exists!'
else
echo 'illegal result!'
imgresult = enablecpe $esn2 $tenantid "IMG"
if [ $imgresult -eq 201 ]; then
echo 'cpe $esn2 has been successfully enabled!'
elif [ $cpe2result -eq 404 ]; then
echo 'tenant $tenantid not exits!'
elif [ $cpe2result -eq 409 ]; then
echo 'cpe $esn2 already exists!'
else
echo 'illegal result!'
while true
do
sleep 30
ucpestatus = checkstatus $esn1
imgstatus = checkstatus $esn2
if [ $ucpestatus -eq "Active" ] && [ $imgstatus -eq "Active"]; then
echo 'ucpe and img are both ready for service!'
break
fi
done
ucpeinterfaceresult = cfglaninterface $esn1 $interface1 $vlan1 $ip1
if [ $ucpeinterfaceresult -eq 200 ]; then
echo 'cpe $esn1 interface $interface1 has been successfully configured!'
elif [ $ucpeinterfaceresult -eq 404 ]; then
echo 'cpe $esn1 not exits!'
else
echo 'illegal result!'
imginterfaceresult = cfglaninterface $esn2 $interface2 $vlan2 $ip2
if [ $imginterfaceresult -eq 200 ]; then
echo 'cpe $esn2 interface $interface2 has been successfully configured!'
elif [ $imginterfaceresult -eq 404 ]; then
echo 'cpe $esn1 not exits!'
else
echo 'illegal result!'
serviceresult = enablesite2site $tenantid $esn1 $interface1 $vlan1 $subnet1 $gateway1 $esn2 $interface2 $vlan2 $subnet2 $gateway2
if [ $serviceresult -eq 201 ]; then
echo 'l3vpn has been successfully enabled between cpe $esn1 and cpe $esn2!'
elif [ $serviceresult -eq 404 ]; then
echo 'tenant or cpe not exits!'
elif [ $serviceresult -eq 409 ]; then
echo 'l3vpn already enabled!'
elif [ $serviceresult -eq 500 ]; then
echo $serviceresult
else
echo 'illegal result!'
elif [ $result -eq 409 ]; then
echo 'tenant already exists!'
else
echo 'illegal result!'
fi
|