2 Variables file for tcpmd5user suite.
4 Expected JSON templates are fairly long,
5 therefore there are moved out of testcase file.
6 Also, it is needed to generate base64 encoded tunnel name
7 from Mininet IP (which is not known beforehand),
8 so it is easier to employ Python here,
9 than do manipulation in Robot file.
11 # Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
13 # This program and the accompanying materials are made available under the
14 # terms of the Eclipse Public License v1.0 which accompanies this distribution,
15 # and is available at http://www.eclipse.org/legal/epl-v10.html
18 from string import Template
21 __author__ = "Vratko Polak"
22 __copyright__ = "Copyright(c) 2015, Cisco Systems, Inc."
23 __license__ = "Eclipse Public License v1.0"
24 __email__ = "vrpolak@cisco.com"
27 # FIXME: Migrate values shared by other suites to separate Python module.
30 def get_variables(mininet_ip):
31 """Return dict of variables for the given IPv4 address of Mininet VM."""
32 # TODO: Document in 'V' fashion, as in pcepuser/variables.py using more systematic local variable names.
33 # Dict of variables to return, starts empty and grows as function proceeds.
35 # Given mininet_ip, this will be the sympolic name uf tunnel under test.
36 tunnelname = "pcc_" + mininet_ip + "_tunnel_1"
37 # Base64 code for the symbolic name, as that is present in datastore.
38 tunnelname_bytes = tunnelname.encode("ascii")
39 pathcode_encoded = base64.b64encode(tunnelname_bytes)
40 pathcode = pathcode_encoded.decode("ascii")
41 variables["pcc_name"] = tunnelname
42 variables["pcc_name_code"] = pathcode
43 # JSON response when pcep-topology is ready but no PCC is connected.
49 "topology-id": "pcep-topology",
51 "network-topology-pcep:topology-pcep": {}
56 # Template of JSON response with pcep-topology seeing 1 PCC 1 LSP.
57 onjsontempl = Template(
63 "network-topology-pcep:path-computation-client": {
72 "processing-rule": false,
76 "ip-prefix": "1.1.1.1/32"
83 "odl-pcep-ietf-stateful07:lsp": {
84 "administrative": true,
87 "odl-pcep-ietf-initiated00:create": false,
90 "processing-rule": false,
96 "ipv4-extended-tunnel-id": "$IP",
97 "ipv4-tunnel-endpoint-address": "1.1.1.1",
98 "ipv4-tunnel-sender-address": "$IP"
103 "symbolic-path-name": {
112 "state-sync": "synchronized",
114 "odl-pcep-ietf-stateful07:stateful": {
115 "lsp-update-capability": true,
116 "odl-pcep-ietf-initiated00:initiation": true
120 "node-id": "pcc://$IP"
123 "topology-id": "pcep-topology",
125 "network-topology-pcep:topology-pcep": {}
131 # Dictionly which tells values for placeholders.
132 repl_dict = {"IP": mininet_ip, "NAME": tunnelname, "CODE": pathcode}
133 # The finalized JSON.
134 variables["onjson"] = onjsontempl.substitute(repl_dict)
135 # The following strings are XML data.
136 # See https://wiki.opendaylight.org/view/BGP_LS_PCEP:TCP_MD5_Guide#RESTCONF_Configuration
137 # For curl, string is suitable to became -d argument only after
138 # replacing ' -> '"'"' and enclosing in single quotes.
141 ] = """<module xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
142 <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:tcpmd5:jni:cfg">x:native-key-access-factory</type>
143 <name>global-key-access-factory</name>
147 ] = """<service xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
148 <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:tcpmd5:cfg">x:key-access-factory</type>
150 <name>global-key-access-factory</name>
151 <provider>/modules/module[type='native-key-access-factory'][name='global-key-access-factory']</provider>
155 "client_channel_module"
156 ] = """<module xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
157 <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:tcpmd5:netty:cfg">x:md5-client-channel-factory</type>
158 <name>md5-client-channel-factory</name>
159 <key-access-factory xmlns="urn:opendaylight:params:xml:ns:yang:controller:tcpmd5:netty:cfg">
160 <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:tcpmd5:cfg">x:key-access-factory</type>
161 <name>global-key-access-factory</name>
162 </key-access-factory>
165 "client_channel_service"
166 ] = """<service xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
167 <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:tcpmd5:netty:cfg">x:md5-channel-factory</type>
169 <name>md5-client-channel-factory</name>
170 <provider>/modules/module[type='md5-client-channel-factory'][name='md5-client-channel-factory']</provider>
174 "server_channel_module"
175 ] = """<module xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
176 <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:tcpmd5:netty:cfg">"""
177 # What is your favourite way to concatenate strings without resembling tuple?
179 "server_channel_module"
180 ] += """prefix:md5-server-channel-factory-impl</type>
181 <name>md5-server-channel-factory</name>
182 <server-key-access-factory xmlns="urn:opendaylight:params:xml:ns:yang:controller:tcpmd5:netty:cfg">
183 <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:tcpmd5:cfg">x:key-access-factory</type>
184 <name>global-key-access-factory</name>
185 </server-key-access-factory>
188 "server_channel_service"
189 ] = """<service xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
190 <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:tcpmd5:netty:cfg">"""
192 "server_channel_service"
193 ] += """prefix:md5-server-channel-factory</type>
195 <name>md5-server-channel-factory</name>
196 <provider>/modules/module[type='md5-server-channel-factory-impl'][name='md5-server-channel-factory']</provider>
200 "pcep_dispatcher_module"
201 ] = """<module xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
202 <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:pcep:impl">x:pcep-dispatcher-impl</type>
203 <name>global-pcep-dispatcher</name>
204 <md5-channel-factory xmlns="urn:opendaylight:params:xml:ns:yang:controller:pcep:impl">
205 <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:tcpmd5:netty:cfg">x:md5-channel-factory</type>
206 <name>md5-client-channel-factory</name>
207 </md5-channel-factory>
208 <md5-server-channel-factory xmlns="urn:opendaylight:params:xml:ns:yang:controller:pcep:impl">
209 <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:tcpmd5:netty:cfg">x:md5-server-channel-factory</type>
210 <name>md5-server-channel-factory</name>
211 </md5-server-channel-factory>
213 # Template to set password.
214 passwd_templ = Template(
215 """<module xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
216 <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:pcep:topology:provider">x:pcep-topology-provider</type>
217 <name>pcep-topology</name>
218 <client xmlns="urn:opendaylight:params:xml:ns:yang:controller:pcep:topology:provider">
219 <address xmlns="urn:opendaylight:params:xml:ns:yang:controller:pcep:topology:provider">$IP</address>
223 # We use three template instantiations. No password:
224 repl_dict = {"IP": mininet_ip, "PASSWD": ""}
225 variables["no_passwd_module"] = passwd_templ.substitute(repl_dict)
226 changeme = """ <password>changeme</password>
229 repl_dict = {"IP": mininet_ip, "PASSWD": changeme}
230 variables["passwd_changeme_module"] = passwd_templ.substitute(repl_dict)
231 # and correct password.
232 topsecret = """ <password>topsecret</password>
234 repl_dict = {"IP": mininet_ip, "PASSWD": topsecret}
235 variables["passwd_topsecret_module"] = passwd_templ.substitute(repl_dict)
236 # All variables set, return dict to Robot.