3 # Copyright 2016 RIFT.IO Inc
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
23 import xml
.etree
.ElementTree
as etree
24 from gi
.repository
import RwTopologyYang
as RwTl
26 gi
.require_version('RwYang', '1.0')
27 from gi
.repository
import RwYang
29 gi
.require_version('RwKeyspec', '1.0')
30 from gi
.repository
.RwKeyspec
import quoted_key
33 logger
= logging
.getLogger(__name__
)
36 class SdnSim(core
.Topology
):
38 super(SdnSim
, self
).__init
__()
39 self
._model
= RwYang
.Model
.create_libyang()
40 self
._model
.load_schema_ypbc(RwTl
.get_schema())
42 def get_network_list(self
, account
):
44 Returns the discovered network
46 @param account - a SDN account
50 nwtop
= RwTl
.YangData_IetfNetwork()
51 #topology_source = "/net/boson/home1/rchamart/work/topology/l2_top.xml"
52 if not account
.sdnsim
.has_field('topology_source') or account
.sdnsim
.topology_source
is None:
54 topology_source
= account
.sdnsim
.topology_source
55 logger
.info("Reading topology file: %s", topology_source
)
56 if 'json' in topology_source
:
57 with
open(topology_source
,'r') as f
:
58 print("Reading static topology file")
60 nwtop
.from_json(self
._model
,op_json
)
61 for nw
in nwtop
.network
:
62 nw
.server_provided
= False
63 logger
.debug("...Network id %s", nw
.network_id
)
64 #nw_xpath = ("D,/nd:network[network-id={}]").format(quoted_key(nw.network_id))
65 #xact_info.respond_xpath(rwdts.XactRspCode.MORE,
67 elif 'xml' in topology_source
:
68 tree
= etree
.parse(topology_source
)
70 xmlstr
= etree
.tostring(root
, encoding
="unicode")
72 # The top level topology object does not have XML conversion
73 # Hence going one level down
74 #l2nw1 = nwtop.network.add()
75 #l2nw1.from_xml_v2(self._model, xmlstr)
76 nwtop
.from_xml_v2(self
._model
,xmlstr
)
78 logger
.debug("Returning topology data imported from XML file")