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.
21 import xml
.etree
.ElementTree
as etree
22 from gi
.repository
import RwTopologyYang
as RwTl
25 gi
.require_version('RwYang', '1.0')
26 from gi
.repository
import RwYang
29 logger
= logging
.getLogger(__name__
)
32 class SdnSim(core
.Topology
):
34 super(SdnSim
, self
).__init
__()
35 self
._model
= RwYang
.Model
.create_libncx()
36 self
._model
.load_schema_ypbc(RwTl
.get_schema())
38 def get_network_list(self
, account
):
40 Returns the discovered network
42 @param account - a SDN account
46 nwtop
= RwTl
.YangData_IetfNetwork()
47 #topology_source = "/net/boson/home1/rchamart/work/topology/l2_top.xml"
48 if not account
.sdnsim
.has_field('topology_source') or account
.sdnsim
.topology_source
is None:
50 topology_source
= account
.sdnsim
.topology_source
51 logger
.info("Reading topology file: %s", topology_source
)
52 if 'json' in topology_source
:
53 with
open(topology_source
,'r') as f
:
54 print("Reading static topology file")
56 nwtop
.from_json(self
._model
,op_json
)
57 for nw
in nwtop
.network
:
58 nw
.server_provided
= False
59 logger
.debug("...Network id %s", nw
.network_id
)
60 #nw_xpath = ("D,/nd:network[network-id=\'{}\']").format(nw.network_id)
61 #xact_info.respond_xpath(rwdts.XactRspCode.MORE,
63 elif 'xml' in topology_source
:
64 tree
= etree
.parse(topology_source
)
66 xmlstr
= etree
.tostring(root
, encoding
="unicode")
68 # The top level topology object does not have XML conversion
69 # Hence going one level down
70 #l2nw1 = nwtop.network.add()
71 #l2nw1.from_xml_v2(self._model, xmlstr)
72 nwtop
.from_xml_v2(self
._model
,xmlstr
)
74 logger
.debug("Returning topology data imported from XML file")