Skip to content
Snippets Groups Projects
Commit 26e53051 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Device - gNMI OpenConfig Driver:

- Added logic to free libyang objects on Interface handler
parent 49eafdbd
No related branches found
No related tags found
2 merge requests!359Release TeraFlowSDN 5.0,!299Resolve "(CTTC) Fix CI/CD pipeline end-to-end tests not passing"
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import json, libyang, logging import json, libyang, logging, queue
from typing import Any, Dict, List, Tuple from typing import Any, Dict, List, Tuple
from ._Handler import _Handler from ._Handler import _Handler
from .Tools import get_bool, get_int, get_str from .Tools import get_bool, get_int, get_str
...@@ -43,30 +43,40 @@ class InterfaceHandler(_Handler): ...@@ -43,30 +43,40 @@ class InterfaceHandler(_Handler):
address_prefix = get_int (resource_value, 'address_prefix') # 24 address_prefix = get_int (resource_value, 'address_prefix') # 24
mtu = get_int (resource_value, 'mtu' ) # 1500 mtu = get_int (resource_value, 'mtu' ) # 1500
objects_to_free = queue.LifoQueue[libyang.DContainer]()
yang_ifs : libyang.DContainer = yang_handler.get_data_path('/openconfig-interfaces:interfaces') yang_ifs : libyang.DContainer = yang_handler.get_data_path('/openconfig-interfaces:interfaces')
objects_to_free.put_nowait(yang_ifs)
yang_if_path = 'interface[name="{:s}"]'.format(if_name) yang_if_path = 'interface[name="{:s}"]'.format(if_name)
yang_if : libyang.DContainer = yang_ifs.create_path(yang_if_path) yang_if : libyang.DContainer = yang_ifs.create_path(yang_if_path)
objects_to_free.put_nowait(yang_if)
yang_if.create_path('config/name', if_name ) yang_if.create_path('config/name', if_name )
if enabled is not None: yang_if.create_path('config/enabled', enabled) if enabled is not None: yang_if.create_path('config/enabled', enabled)
if mtu is not None: yang_if.create_path('config/mtu', mtu) if mtu is not None: yang_if.create_path('config/mtu', mtu)
yang_sifs : libyang.DContainer = yang_if.create_path('subinterfaces') yang_sifs : libyang.DContainer = yang_if.create_path('subinterfaces')
objects_to_free.put_nowait(yang_sifs)
yang_sif_path = 'subinterface[index="{:d}"]'.format(sif_index) yang_sif_path = 'subinterface[index="{:d}"]'.format(sif_index)
yang_sif : libyang.DContainer = yang_sifs.create_path(yang_sif_path) yang_sif : libyang.DContainer = yang_sifs.create_path(yang_sif_path)
objects_to_free.put_nowait(yang_sif)
yang_sif.create_path('config/index', sif_index) yang_sif.create_path('config/index', sif_index)
if enabled is not None: yang_sif.create_path('config/enabled', enabled) if enabled is not None: yang_sif.create_path('config/enabled', enabled)
if vlan_id is not None: if vlan_id is not None:
yang_subif_vlan : libyang.DContainer = yang_sif.create_path('openconfig-vlan:vlan') yang_subif_vlan : libyang.DContainer = yang_sif.create_path('openconfig-vlan:vlan')
objects_to_free.put_nowait(yang_subif_vlan)
yang_subif_vlan.create_path('match/single-tagged/config/vlan-id', vlan_id) yang_subif_vlan.create_path('match/single-tagged/config/vlan-id', vlan_id)
yang_ipv4 : libyang.DContainer = yang_sif.create_path('openconfig-if-ip:ipv4') yang_ipv4 : libyang.DContainer = yang_sif.create_path('openconfig-if-ip:ipv4')
objects_to_free.put_nowait(yang_ipv4)
if enabled is not None: yang_ipv4.create_path('config/enabled', enabled) if enabled is not None: yang_ipv4.create_path('config/enabled', enabled)
if address_ip is not None and address_prefix is not None: if address_ip is not None and address_prefix is not None:
yang_ipv4_addrs : libyang.DContainer = yang_ipv4.create_path('addresses') yang_ipv4_addrs : libyang.DContainer = yang_ipv4.create_path('addresses')
objects_to_free.put_nowait(yang_ipv4_addrs)
yang_ipv4_addr_path = 'address[ip="{:s}"]'.format(address_ip) yang_ipv4_addr_path = 'address[ip="{:s}"]'.format(address_ip)
yang_ipv4_addr : libyang.DContainer = yang_ipv4_addrs.create_path(yang_ipv4_addr_path) yang_ipv4_addr : libyang.DContainer = yang_ipv4_addrs.create_path(yang_ipv4_addr_path)
objects_to_free.put_nowait(yang_ipv4_addr)
yang_ipv4_addr.create_path('config/ip', address_ip) yang_ipv4_addr.create_path('config/ip', address_ip)
yang_ipv4_addr.create_path('config/prefix-length', address_prefix) yang_ipv4_addr.create_path('config/prefix-length', address_prefix)
...@@ -75,6 +85,10 @@ class InterfaceHandler(_Handler): ...@@ -75,6 +85,10 @@ class InterfaceHandler(_Handler):
json_data = json.loads(str_data) json_data = json.loads(str_data)
json_data = json_data['openconfig-interfaces:interface'][0] json_data = json_data['openconfig-interfaces:interface'][0]
str_data = json.dumps(json_data) str_data = json.dumps(json_data)
while not objects_to_free.empty():
obj = objects_to_free.get()
obj.free()
return str_path, str_data return str_path, str_data
def parse( def parse(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment