2 from ipaddr import IPAddress
3 from string import Template
7 """Gets modulo of number
9 :param num: Number to be used
11 :param base: Base used
13 :returns: Int representing modulo of specified numbers.
16 return int(num) % int(base)
19 def get_ip_from_number(n):
20 """Generate string representing Ipv4 from specified number that is added number 2130706432
22 :param n: Number to be converted
24 :returns: String containing Ipv4.
27 ip = IPAddress(2130706432 + n)
31 def lower_version(ver1, ver2):
32 """Generate xml containing SGT mach data
34 :param ver1: Version of SXP protocol for compare
36 :param ver2: Version of SXP protocol for compare
38 :returns: String containing lower from those two specified versions.
49 def get_filter_entry(seq, entry_type, sgt="", esgt="", acl="", eacl="", pl="", epl="", ps=""):
50 """Generate xml containing FilterEntry data
52 :param seq: Sequence of entry
54 :param entry_type: Type of entry (permit/deny)
55 :type entry_type: string
56 :param sgt: SGT matches to be added to entry
58 :param esgt: SGT ranges match to be added to entry
60 :param acl: ACL matches to be added to entry
62 :param eacl: EACL matches to be added to entry
64 :param pl: PrefixList matches to be added to entry
66 :param epl: ExtendedPrefixList matches to be added to entry
68 :param ps: PeerSequence matches to be added to entry
70 :returns: String containing xml data for request
74 # Generate XML request containing combination of Matches of different types
77 entries += add_sgt_matches_xml(args)
79 args = esgt.split(',')
80 entries += add_sgt_range_xml(args[0], args[1])
82 entries += add_pl_entry_xml(pl)
85 entries += add_epl_entry_xml(args[0], args[1], args[2])
88 entries += add_acl_entry_xml(args[0], args[1])
90 args = eacl.split(',')
91 entries += add_eacl_entry_xml(args[0], args[1], args[2], args[3])
94 entries += add_ps_entry_xml(args[0], args[1])
95 # Wrap entries in ACL/PrefixList according to specified values
97 return add_pl_entry_default_xml(seq, entry_type, entries)
99 return add_ps_entry_default_xml(seq, entry_type, entries)
100 return add_acl_entry_default_xml(seq, entry_type, entries)
103 def add_peers(*args):
104 """Generate xml containing Peer mach data
106 :param args: Peers data
108 :returns: String containing xml data for request
113 <peer-address>$ip</peer-address>
116 for count, value in enumerate(args):
117 peers += templ.substitute({'ip': value})
121 def add_domains(*args):
122 """Generate xml containing Domain mach data
124 :param args: Domain data
126 :returns: String containing xml data for request
134 for count, value in enumerate(args):
135 peers += templ.substitute({'name': value})
139 def add_sgt_matches_xml(sgt_entries):
140 """Generate xml containing SGT mach data
142 :param sgt_entries: SGT matches
143 :type sgt_entries: string
144 :returns: String containing xml data for request
148 <matches>$sgt</matches>''')
150 for sgt in sgt_entries:
151 matches += templ.substitute({'sgt': sgt})
155 def add_sgt_range_xml(start, end):
156 """Generate xml containing SGT RangeMach data
158 :param start: Start range of SGT
160 :param end: End range of SGT
162 :returns: String containing xml data for request
166 <sgt-start>$start</sgt-start>
167 <sgt-end>$end</sgt-end>''')
168 match = templ.substitute({'start': start, 'end': end})
172 def add_acl_entry_default_xml(seq, entry_type, acl_entries):
173 """Generate xml containing AccessList data
175 :param seq: Sequence of PrefixList entry
177 :param entry_type: Entry type (permit/deny)
178 :type entry_type: string
179 :param acl_entries: XML data containing AccessList entries
180 :type acl_entries: string
181 :returns: String containing xml data for request
186 <entry-type>$entry_type</entry-type>
187 <entry-seq>$seq</entry-seq>$acl_entries
189 matches = templ.substitute(
190 {'seq': seq, 'entry_type': entry_type, 'acl_entries': acl_entries})
194 def add_acl_entry_xml(ip, mask):
195 """Generate xml containing AccessList data
197 :param ip: Ipv4/6 address
199 :param mask: Ipv4/6 wildcard mask
201 :returns: String containing xml data for request
206 <ip-address>$ip</ip-address>
207 <wildcard-mask>$mask</wildcard-mask>
209 return templ.substitute({'ip': ip, 'mask': mask})
212 def add_eacl_entry_xml(ip, mask, amask, wmask):
213 """Generate xml containing ExtendedAccessList data
215 :param ip: Ipv4/6 address
217 :param mask: Ipv4/6 wildcard mask
219 :param amask: Ipv4/6 address mask
221 :param wmask: Ipv4/6 address wildcard mask
223 :returns: String containing xml data for request
228 <ip-address>$ip</ip-address>
229 <wildcard-mask>$mask</wildcard-mask>
231 <address-mask>$amask</address-mask>
232 <wildcard-mask>$wmask</wildcard-mask>
235 return templ.substitute({'ip': ip, 'mask': mask, 'amask': amask, 'wmask': wmask})
238 def add_ps_entry_default_xml(seq, entry_type, ps_entries):
239 """Generate xml containing PeerSequence data
241 :param seq: Sequence of PrefixList entry
243 :param entry_type: Entry type (permit/deny)
244 :type entry_type: string
245 :param ps_entries: XML data containing PeerSequence entries
246 :type ps_entries: string
247 :returns: String containing xml data for request
251 <peer-sequence-entry xmlns="urn:opendaylight:sxp:controller">
252 <entry-type>$entry_type</entry-type>
253 <entry-seq>$seq</entry-seq>$ps_entries
254 </peer-sequence-entry>''')
255 return templ.substitute({'seq': seq, 'entry_type': entry_type, 'ps_entries': ps_entries})
258 def add_pl_entry_default_xml(seq, entry_type, pl_entries):
259 """Generate xml containing PrefixList data
261 :param seq: Sequence of PrefixList entry
263 :param entry_type: Entry type (permit/deny)
264 :type entry_type: string
265 :param pl_entries: XML data containing PrefixList entries
266 :type pl_entries: string
267 :returns: String containing xml data for request
271 <prefix-list-entry xmlns="urn:opendaylight:sxp:controller">
272 <entry-type>$entry_type</entry-type>
273 <entry-seq>$seq</entry-seq>$pl_entries
274 </prefix-list-entry>''')
275 return templ.substitute({'seq': seq, 'entry_type': entry_type, 'pl_entries': pl_entries})
278 def add_pl_entry_xml(prefix):
279 """Generate xml containing PrefixList data
281 :param prefix: Ipv4/6 prefix
283 :returns: String containing xml data for request
288 <ip-prefix>$prefix</ip-prefix>
289 </prefix-list-match>''')
290 return templ.substitute({'prefix': prefix})
293 def add_epl_entry_xml(prefix, op, mask):
294 """Generate xml containing Extended PrefixList data
296 :param prefix: Ipv4/6 prefix
298 :param op: PrefixList option (ge/le/eq)
300 :param mask: Ipv4/6 Mask
302 :returns: String containing xml data for request
307 <ip-prefix>$prefix</ip-prefix>
309 <mask-range>$op</mask-range>
310 <mask-value>$mask</mask-value>
312 </prefix-list-match>''')
313 return templ.substitute({'prefix': prefix, 'mask': mask, 'op': op})
316 def add_ps_entry_xml(op, length):
317 """Generate xml containing Extended PrefixList data
319 :param op: PrefixList option (ge/le/eq)
321 :param length: PeerSequence length
323 :returns: String containing xml data for request
327 <peer-sequence-length>$length</peer-sequence-length>
328 <peer-sequence-range>$op</peer-sequence-range>
330 return templ.substitute({'length': length, 'op': op})
333 def parse_peer_groups(groups_json):
334 """Parse JSON string into Array of PeerGroups
336 :param groups_json: JSON containing PeerGroups
337 :type groups_json: string
338 :returns: Array containing PeerGroups.
341 data = json.loads(groups_json)
342 groups = data['output']
344 for group in groups.values():
349 def parse_connections(connections_json):
350 """Parse JSON string into Array of Connections
352 :param connections_json: JSON containing Connections
353 :type connections_json: string
354 :returns: Array containing Connections.
357 data = json.loads(connections_json)
358 connections = data['output']['connections']
360 for connection in connections.values():
365 def find_connection(connections_json, version, mode, ip, port, state):
366 """Test if Connection with specified values is contained in JSON
368 :param connections_json: JSON containing Connections
369 :type connections_json: string
370 :param version: Version of SXP protocol (version1/2/3/4)
371 :type version: string
372 :param mode: Mode of SXP peer (speaker/listener/both)
374 :param ip: Ipv4/6 address of remote peer
376 :param port: Port on with remote peer listens
378 :param state: State of connection (on/off/pendingOn/deleteHoldDown)
380 :returns: True if Connection with specified params was found, otherwise False.
383 for connection in parse_connections(connections_json):
384 if (connection['peer-address'] == ip and connection['tcp-port'] == int(port) and connection['mode'] == mode and
385 connection['version'] == version):
388 elif connection['state'] == state:
393 def parse_bindings(bindings_json):
394 """Parse JSON string into Array of Bindings
396 :param bindings_json: JSON containing Bindings
397 :type bindings_json: string
398 :returns: Array containing Bindings.
401 data = json.loads(bindings_json)
403 for bindings_json in data['output'].values():
404 for binding in bindings_json:
405 output.append(binding)
409 def find_binding(bindings, sgt, prefix):
410 """Test if Binding with specified values is contained in JSON
412 :param bindings: JSON containing Bindings
413 :type bindings: string
414 :param sgt: Source Group Tag
416 :param prefix: Ipv4/6 prefix
418 :returns: True if Binding with specified params was found, otherwise False.
421 for binding in parse_bindings(bindings):
422 if binding['sgt'] == int(sgt):
423 for ip_prefix in binding['ip-prefix']:
424 if ip_prefix == prefix:
429 def parse_prefix_groups(prefix_groups_json, source_):
430 """Parse JSON string into Array of PrefixGroups
432 :param prefix_groups_json: JSON containing PrefixGroups
433 :type prefix_groups_json: string
434 :param source_: Source of PrefixGroups (sxp/local)
435 :type source_: string
436 :returns: Array containing PrefixGroups.
439 data = json.loads(prefix_groups_json)
440 bindings = data['sxp-node:master-database']
442 for binding in bindings.values():
443 for binding_source in binding:
444 if source_ == "any" or binding_source['binding-source'] == source_:
445 for prefix_group in binding_source['prefix-group']:
446 output.append(prefix_group)
450 def find_binding_legacy(prefix_groups_json, sgt, prefix, source_, action):
451 """Test if Binding with specified values is contained in JSON
453 :param prefix_groups_json: JSON containing Bindings and PrefixGroups
454 :type prefix_groups_json: string
455 :param sgt: Source Group Tag
457 :param prefix: Ipv4/6 prefix
459 :param source_: Source of binding (local/sxp)
460 :type source_: string
461 :param action: Action for binding (add/delete)
463 :returns: True if Binding with specified params was found, otherwise False.
467 for prefixgroup in parse_prefix_groups(prefix_groups_json, source_):
468 if prefixgroup['sgt'] == int(sgt):
469 for binding in prefixgroup['binding']:
470 if binding['ip-prefix'] == prefix and binding['action'] == action:
475 def add_entry_xml(sgt, prefix, ip, domain_name):
476 """Generate xml for Add Bindings request
478 :param sgt: Source Group Tag
480 :param prefix: Ipv4/6 prefix
482 :param ip: Ipv4 address of node
484 :param domain_name: Name of Domain
485 :type domain_name: string
486 :returns: String containing xml data for request
489 templ = Template('''<input>
490 <requested-node xmlns="urn:opendaylight:sxp:controller">$ip</requested-node>
492 <sgt xmlns="urn:opendaylight:sxp:controller">$sgt</sgt>
493 <ip-prefix xmlns="urn:opendaylight:sxp:controller">$prefix</ip-prefix>
495 data = templ.substitute({'sgt': sgt, 'prefix': prefix, 'ip': ip, 'domain': get_domain_name(domain_name)})
499 def add_connection_xml(version, mode, ip, port, node, password_, domain_name):
500 """Generate xml for Add Connection request
502 :param version: Version of SXP protocol (version1/2/3/4)
503 :type version: string
504 :param mode: Mode of SXP peer (speaker/listener/both)
506 :param ip: Ipv4/6 address of remote peer
508 :param port: Port on with remote peer listens
510 :param node: Ipv4 address of node
512 :param password_: Password type (none/default)
513 :type password_: string
514 :param domain_name: Name of Domain
515 :type domain_name: string
516 :returns: String containing xml data for request
519 templ = Template('''<input>
520 <requested-node xmlns="urn:opendaylight:sxp:controller">$node</requested-node>
522 <connections xmlns="urn:opendaylight:sxp:controller">
524 <peer-address>$ip</peer-address>
525 <tcp-port>$port</tcp-port>
526 <password>$password_</password>
528 <version>$version</version>
529 <description>Connection to ISR-G2</description>
531 <hold-time-min-acceptable>45</hold-time-min-acceptable>
532 <keep-alive-time>30</keep-alive-time>
533 <reconciliation-time>120</reconciliation-time>
539 data = templ.substitute(
540 {'ip': ip, 'port': port, 'mode': mode, 'version': version, 'node': node,
541 'password_': password_, 'domain': get_domain_name(domain_name)})
545 def delete_connections_xml(address, port, node, domain_name):
546 """Generate xml for Delete Connection request
548 :param address: Ipv4/6 address of remote peer
549 :type address: string
550 :param port: Port on with remote peer listens
552 :param node: Ipv4 address of node
554 :param domain_name: Name of Domain
555 :type domain_name: string
556 :returns: String containing xml data for request
559 templ = Template('''<input>
560 <requested-node xmlns="urn:opendaylight:sxp:controller">$node</requested-node>
562 <peer-address xmlns="urn:opendaylight:sxp:controller">$address</peer-address>
563 <tcp-port xmlns="urn:opendaylight:sxp:controller">$port</tcp-port>
565 data = templ.substitute({'address': address, 'port': port, 'node': node, 'domain': get_domain_name(domain_name)})
569 def update_binding_xml(sgt0, prefix0, sgt1, prefix1, ip, domain_name):
570 """Generate xml for Update Binding request
572 :param sgt0: Original Source Group Tag
574 :param prefix0: Original Ipv4/6 prefix
575 :type prefix0: string
576 :param sgt1: New Source Group Tag
578 :param prefix1: New Ipv4/6 prefix
579 :type prefix1: string
580 :param ip: Ipv4 address of node
582 :param domain_name: Name of Domain
583 :type domain_name: string
584 :returns: String containing xml data for request
587 templ = Template('''<input>
588 <requested-node xmlns="urn:opendaylight:sxp:controller">$ip</requested-node>
590 <original-binding xmlns="urn:opendaylight:sxp:controller">
592 <ip-prefix>$prefix0</ip-prefix>
594 <new-binding xmlns="urn:opendaylight:sxp:controller">
596 <ip-prefix>$prefix1</ip-prefix>
599 data = templ.substitute(
600 {'sgt0': sgt0, 'sgt1': sgt1, 'prefix0': prefix0, 'prefix1': prefix1, 'ip': ip,
601 'domain': get_domain_name(domain_name)})
605 def delete_binding_xml(sgt, prefix, ip, domain_name):
606 """Generate xml for Delete Binding request
608 :param sgt: Source Group Tag
610 :param prefix: Ipv4/6 prefix
612 :param ip: Ipv4 address of node
614 :param domain_name: Name of Domain
615 :type domain_name: string
616 :returns: String containing xml data for request
619 templ = Template('''<input>
620 <requested-node xmlns="urn:opendaylight:sxp:controller">$ip</requested-node>
621 <sgt xmlns="urn:opendaylight:sxp:controller">$sgt</sgt>
622 <ip-prefix xmlns="urn:opendaylight:sxp:controller">$prefix</ip-prefix>
625 data = templ.substitute({'sgt': sgt, 'prefix': prefix, 'ip': ip, 'domain': get_domain_name(domain_name)})
629 def add_peer_group_xml(name, peers, ip):
630 """Generate xml for Add PeerGroups request
632 :param name: Name of PeerGroup
634 :param peers: XML formatted peers that will be added to group
636 :param ip: Ipv4 address of node
638 :returns: String containing xml data for request
641 templ = Template('''<input>
642 <requested-node xmlns="urn:opendaylight:sxp:controller">$ip</requested-node>
643 <sxp-peer-group xmlns="urn:opendaylight:sxp:controller">
644 <name xmlns="urn:opendaylight:sxp:controller">$name</name>
645 <sxp-peers xmlns="urn:opendaylight:sxp:controller">$peers</sxp-peers>
648 data = templ.substitute({'name': name, 'peers': peers, 'ip': ip})
652 def delete_peer_group_xml(name, ip):
653 """Generate xml for Delete PeerGroup request
655 :param name: Name of PeerGroup
657 :param ip: Ipv4 address of node
659 :returns: String containing xml data for request
662 templ = Template('''<input>
663 <requested-node xmlns="urn:opendaylight:sxp:controller">$ip</requested-node>
664 <peer-group-name xmlns="urn:opendaylight:sxp:controller">$name</peer-group-name>
666 data = templ.substitute({'name': name, 'ip': ip})
670 def get_peer_groups_from_node_xml(ip):
671 """Generate xml for Get PeerGroups request
673 :param ip: Ipv4 address of node
675 :returns: String containing xml data for request
678 templ = Template('''<input>
679 <requested-node xmlns="urn:opendaylight:sxp:controller">$ip</requested-node>
681 data = templ.substitute({'ip': ip})
685 def add_filter_xml(group, filter_type, entries, ip):
686 """Generate xml for Add Filter request
688 :param group: Name of group containing filter
690 :param filter_type: Type of filter
691 :type filter_type: string
692 :param entries: XML formatted entries that will be added in filter
693 :type entries: string
694 :param ip: Ipv4 address of node
696 :returns: String containing xml data for request
699 templ = Template('''<input>
700 <requested-node xmlns="urn:opendaylight:sxp:controller">$ip</requested-node>
701 <peer-group-name xmlns="urn:opendaylight:sxp:controller">$group</peer-group-name>
702 <sxp-filter xmlns="urn:opendaylight:sxp:controller">
703 <filter-type>$filter_type</filter-type>$entries
706 data = templ.substitute(
707 {'group': group, 'filter_type': filter_type, 'ip': ip, 'entries': entries})
711 def add_domain_filter_xml(domain, domains, entries, ip, filter_name=None):
712 """Generate xml for Add Domain Filter request
714 :param domain: Name of Domain containing filter
716 :param domains: Domains on which filter will be applied
717 :type domains: string
718 :param entries: XML formatted entries that will be added in filter
719 :type entries: string
720 :param ip: Ipv4 address of node
722 :param filter_name: Name of filter
723 :type filter_name: string
724 :returns: String containing xml data for request
728 filter_name = "<filter-name>" + filter_name + "</filter-name>"
729 templ = Template('''<input>
730 <requested-node xmlns="urn:opendaylight:sxp:controller">$ip</requested-node>
731 <domain-name xmlns="urn:opendaylight:sxp:controller">$domain</domain-name>
732 <sxp-domain-filter xmlns="urn:opendaylight:sxp:controller">
734 <domains>$domains</domains>
738 data = templ.substitute(
739 {'domain': domain, 'domains': domains, 'ip': ip, 'entries': entries, 'filter_name': filter_name})
743 def delete_filter_xml(group, filter_type, ip):
744 """Generate xml for Delete Filter request
746 :param group: Name of group containing filter
748 :param filter_type: Type of filter
749 :type filter_type: string
750 :param ip: Ipv4 address of node
752 :returns: String containing xml data for request
755 templ = Template('''<input>
756 <requested-node xmlns="urn:opendaylight:sxp:controller">$ip</requested-node>
757 <peer-group-name xmlns="urn:opendaylight:sxp:controller">$group</peer-group-name>
758 <filter-type xmlns="urn:opendaylight:sxp:controller">$filter_type</filter-type>
760 data = templ.substitute(
761 {'group': group, 'filter_type': filter_type, 'ip': ip})
765 def delete_domain_filter_xml(domain, ip, filter_name=None):
766 """Generate xml for Delete Filter request
768 :param domain: Name of Domain containing filter
770 :param ip: Ipv4 address of node
772 :param filter_name: Name of filter
773 :type filter_name: string
774 :returns: String containing xml data for request
778 filter_name = '<filter-name xmlns="urn:opendaylight:sxp:controller">' + filter_name + "</filter-name>"
779 templ = Template('''<input>
780 <requested-node xmlns="urn:opendaylight:sxp:controller">$ip</requested-node>
781 <domain-name xmlns="urn:opendaylight:sxp:controller">$domain</domain-name>
784 data = templ.substitute(
785 {'domain': domain, 'ip': ip, 'filter_name': filter_name})
789 def get_connections_from_node_xml(ip, domain_name):
790 """Generate xml for Get Connections request
792 :param ip: Ipv4 address of node
794 :param domain_name: Name of Domain
795 :type domain_name: string
796 :returns: String containing xml data for request
799 templ = Template('''<input>
800 <requested-node xmlns="urn:opendaylight:sxp:controller">$ip</requested-node>
803 data = templ.substitute({'ip': ip, 'domain': get_domain_name(domain_name)})
807 def get_bindings_from_node_xml(ip, binding_range, domain_name):
808 """Generate xml for Get Bindings request
810 :param binding_range: All or only Local bindings
811 :type binding_range: string
812 :param ip: Ipv4 address of node
814 :param domain_name: Name of Domain
815 :type domain_name: string
816 :returns: String containing xml data for request
819 templ = Template('''<input>
820 <requested-node xmlns="urn:opendaylight:sxp:controller">$ip</requested-node>
821 <bindings-range xmlns="urn:opendaylight:sxp:controller">$range</bindings-range>
824 data = templ.substitute({'ip': ip, 'range': binding_range, 'domain': get_domain_name(domain_name)})
828 def add_node_xml(node_id, port, password, version, node_ip=None, expansion=0):
829 """Generate xml for Add Node request
831 :param node_id: Ipv4 address formatted node id
832 :type node_id: string
833 :param node_ip: Ipv4 address of node
834 :type node_ip: string
835 :param port: Node port number
837 :param expansion: Bindings expansion
839 :returns: String containing xml data for request
844 templ = Template('''<input xmlns="urn:opendaylight:sxp:controller">
845 <node-id>$id</node-id>
847 <retry-open-time>1</retry-open-time>
848 <hold-time-min-acceptable>120</hold-time-min-acceptable>
849 <delete-hold-down-time>120</delete-hold-down-time>
850 <hold-time-min>90</hold-time-min>
851 <reconciliation-time>120</reconciliation-time>
852 <hold-time>90</hold-time>
853 <hold-time-max>180</hold-time-max>
854 <keep-alive-time>30</keep-alive-time>
856 <mapping-expanded>$expansion</mapping-expanded>
858 <password>$password</password>
860 <tcp-port>$port</tcp-port>
861 <version>$version</version>
862 <description>ODL SXP Controller</description>
863 <source-ip>$ip</source-ip>
864 <master-database></master-database>
866 data = templ.substitute(
867 {'ip': node_ip, 'id': node_id, 'port': port, 'password': password, 'version': version, 'expansion': expansion})
871 def delete_node_xml(node_id):
872 """Generate xml for Delete node request
874 :param node_id: Ipv4 address formatted node id
875 :type node_id: string
876 :returns: String containing xml data for request
879 templ = Template('''<input xmlns="urn:opendaylight:sxp:controller">
880 <node-id>$id</node-id>
882 data = templ.substitute({'id': node_id})
886 def add_domain_xml(node_id, name):
887 """Generate xml for Add Domain request
889 :param node_id: Id of node
890 :type node_id: string
891 :param name: Name of Domain
893 :returns: String containing xml data for request
896 templ = Template('''<input>
897 <node-id xmlns="urn:opendaylight:sxp:controller">$id</node-id>
898 <domain-name xmlns="urn:opendaylight:sxp:controller">$name</domain-name>
900 data = templ.substitute({'name': name, 'id': node_id})
904 def delete_domain_xml(node_id, name):
905 """Generate xml for Remove Domain request
907 :param node_id: Id of node
908 :type node_id: string
909 :param name: Name of Domain
911 :returns: String containing xml data for request
914 return add_domain_xml(name, node_id)
917 def get_domain_name(domain_name):
918 """Generate xml for Get Bindings request
920 :param domain_name: Name of Domain
921 :type domain_name: string
922 :returns: String containing xml data for request
925 if domain_name == 'global':
928 return '<domain-name xmlns="urn:opendaylight:sxp:controller">' + domain_name + '</domain-name>'
931 def add_bindings_xml(node_id, domain, sgt, prefixes):
932 """Generate xml for Add Bindings request
934 :param node_id: Id of node
935 :type node_id: string
936 :param domain: Name of Domain
938 :param sgt: Security group
940 :param prefixes: List of ip-prefixes
941 :type prefixes: string
942 :returns: String containing xml data for request
946 for prefix in prefixes.split(','):
947 bindings += '\n' + '<ip-prefix>' + prefix + '</ip-prefix>'
948 templ = Template('''<input>
949 <node-id xmlns="urn:opendaylight:sxp:controller">$id</node-id>
950 <domain-name xmlns="urn:opendaylight:sxp:controller">$name</domain-name>
951 <binding xmlns="urn:opendaylight:sxp:controller">
956 data = templ.substitute({'name': domain, 'id': node_id, 'sgt': sgt, 'bindings': bindings})
960 def delete_bindings_xml(node_id, domain, sgt, prefixes):
961 """Generate xml for Remove Bindings request
963 :param node_id: Id of node
964 :type node_id: string
965 :param domain: Name of Domain
967 :param sgt: Security group
969 :param prefixes: List of ip-prefixes
970 :type prefixes: string
971 :returns: String containing xml data for request
974 return add_bindings_xml(node_id, domain, sgt, prefixes)
977 def prefix_range(start, end):
978 """Generate and concatenate ip-prefixes
980 :param start: Start index
982 :param end: End index
984 :returns: String containing concatenated ip-prefixes
992 prefixes += get_ip_from_number(start + index) + '/32'