Testplan, suite, variables and support library for basic PCEP testing.
[integration/test.git] / test / csit / variables / basicpcep / variables.py
1 """Variables file for basicpcep suite.
2
3 Expected JSON templates are fairly long,
4 therefore there are moved out of testcase file.
5 Also, it is needed to generate base64 encoded tunnel name
6 from Mininet IP (which is not known beforehand),
7 so it is easier to employ Python here,
8 than do manipulation in Robot file."""
9 # Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
10 #
11 # This program and the accompanying materials are made available under the
12 # terms of the Eclipse Public License v1.0 which accompanies this distribution,
13 # and is available at http://www.eclipse.org/legal/epl-v10.html
14
15 __author__ = "Vratko Polak"
16 __copyright__ = "Copyright(c) 2015, Cisco Systems, Inc."
17 __license__ = "Eclipse Public License v1.0"
18 __email__ = "vrpolak@cisco.com"
19
20 import binascii
21 from string import Template
22
23
24 def get_variables(mininet_ip):
25     """Return dict of variables for the given IP addtess of Mininet VM."""
26     tunnelname = 'pcc_' + mininet_ip + '_tunnel_1'
27     pathcode = binascii.b2a_base64(tunnelname)[:-1]  # remove endline
28     offjson = '''{
29  "topology": [
30   {
31    "topology-id": "pcep-topology",
32    "topology-types": {
33     "network-topology-pcep:topology-pcep": {}
34    }
35   }
36  ]
37 }'''
38     onjsontempl = Template('''{
39  "topology": [
40   {
41    "node": [
42     {
43      "network-topology-pcep:path-computation-client": {
44       "ip-address": "$IP",
45       "reported-lsp": [
46        {
47         "name": "$NAME",
48         "path": [
49          {
50           "ero": {
51            "ignore": false,
52            "processing-rule": false,
53            "subobject": [
54             {
55              "ip-prefix": {
56               "ip-prefix": "1.1.1.1/32"
57              },
58              "loose": false
59             }
60            ]
61           },
62           "lsp-id": 1,
63           "odl-pcep-ietf-stateful07:lsp": {
64            "administrative": true,
65            "delegate": true,
66            "ignore": false,
67            "odl-pcep-ietf-initiated00:create": false,
68            "operational": "up",
69            "plsp-id": 1,
70            "processing-rule": false,
71            "remove": false,
72            "sync": true,
73            "tlvs": {
74             "lsp-identifiers": {
75              "ipv4": {
76               "ipv4-extended-tunnel-id": "$IP",
77               "ipv4-tunnel-endpoint-address": "1.1.1.1",
78               "ipv4-tunnel-sender-address": "$IP"
79              },
80              "lsp-id": 1,
81              "tunnel-id": 1
82             },
83             "symbolic-path-name": {
84              "path-name": "$CODE"
85             }
86            }
87           }
88          }
89         ]
90        }
91       ],
92       "state-sync": "synchronized",
93       "stateful-tlv": {
94        "odl-pcep-ietf-stateful07:stateful": {
95         "lsp-update-capability": true,
96         "odl-pcep-ietf-initiated00:initiation": true
97        }
98       }
99      },
100      "node-id": "pcc://$IP"
101     }
102    ],
103    "topology-id": "pcep-topology",
104    "topology-types": {
105     "network-topology-pcep:topology-pcep": {}
106    }
107   }
108  ]
109 }''')
110     repl_dict = {'IP': mininet_ip, 'NAME': tunnelname, 'CODE': pathcode}
111     onjson = onjsontempl.substitute(repl_dict)
112     variables = {'offjson': offjson, 'onjson': onjson}
113     return variables