X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=rwlaunchpad%2Fplugins%2Frwvns%2Frift%2Ftopmgr%2Fsdnsim.py;fp=rwlaunchpad%2Fplugins%2Frwvns%2Frift%2Ftopmgr%2Fsdnsim.py;h=4a6b93b000d6f9950cb2421a5bf581d806850e85;hb=6f07e6f33f751ab4ffe624f6037f887b243bece2;hp=0000000000000000000000000000000000000000;hpb=72a563886272088feb7cb52e4aafbe6d2c580ff9;p=osm%2FSO.git diff --git a/rwlaunchpad/plugins/rwvns/rift/topmgr/sdnsim.py b/rwlaunchpad/plugins/rwvns/rift/topmgr/sdnsim.py new file mode 100644 index 00000000..4a6b93b0 --- /dev/null +++ b/rwlaunchpad/plugins/rwvns/rift/topmgr/sdnsim.py @@ -0,0 +1,76 @@ + +# +# Copyright 2016 RIFT.IO Inc +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +from . import core +import logging + +import xml.etree.ElementTree as etree +from gi.repository import RwTopologyYang as RwTl + +import gi +gi.require_version('RwYang', '1.0') +from gi.repository import RwYang + + +logger = logging.getLogger(__name__) + + +class SdnSim(core.Topology): + def __init__(self): + super(SdnSim, self).__init__() + self._model = RwYang.Model.create_libncx() + self._model.load_schema_ypbc(RwTl.get_schema()) + + def get_network_list(self, account): + """ + Returns the discovered network + + @param account - a SDN account + + """ + + nwtop = RwTl.YangData_IetfNetwork() + #topology_source = "/net/boson/home1/rchamart/work/topology/l2_top.xml" + if not account.sdnsim.has_field('topology_source') or account.sdnsim.topology_source is None: + return nwtop + topology_source = account.sdnsim.topology_source + logger.info("Reading topology file: %s", topology_source) + if 'json' in topology_source: + with open(topology_source,'r') as f: + print("Reading static topology file") + op_json = f.read() + nwtop.from_json(self._model,op_json) + for nw in nwtop.network: + nw.server_provided = False + logger.debug("...Network id %s", nw.network_id) + #nw_xpath = ("D,/nd:network[network-id=\'{}\']").format(nw.network_id) + #xact_info.respond_xpath(rwdts.XactRspCode.MORE, + # nw_xpath, nw) + elif 'xml' in topology_source: + tree = etree.parse(topology_source) + root = tree.getroot() + xmlstr = etree.tostring(root, encoding="unicode") + + # The top level topology object does not have XML conversion + # Hence going one level down + #l2nw1 = nwtop.network.add() + #l2nw1.from_xml_v2(self._model, xmlstr) + nwtop.from_xml_v2(self._model,xmlstr) + + logger.debug("Returning topology data imported from XML file") + + return nwtop