Loading src/device/Dockerfile +19 −2 Original line number Diff line number Diff line Loading @@ -53,6 +53,21 @@ RUN python3 -m grpc_tools.protoc -I=. --python_out=. --grpc_python_out=. *.proto RUN rm *.proto RUN find . -type f -exec sed -i -E 's/(import\ .*)_pb2/from . \1_pb2/g' {} \; # Download, build and install libyang. Note that APT package is outdated # - Ref: https://github.com/CESNET/libyang # - Ref: https://github.com/CESNET/libyang-python/ RUN apt-get --yes --quiet --quiet update && \ apt-get --yes --quiet --quiet install build-essential cmake libpcre2-dev python3-dev python3-cffi && \ rm -rf /var/lib/apt/lists/* RUN mkdir -p /var/libyang RUN git clone https://github.com/CESNET/libyang.git /var/libyang RUN mkdir -p /var/libyang/build WORKDIR /var/libyang/build RUN cmake -D CMAKE_BUILD_TYPE:String="Release" .. RUN make RUN make install RUN ldconfig # Create component sub-folders, get specific Python packages RUN mkdir -p /var/teraflow/device WORKDIR /var/teraflow/device Loading @@ -62,9 +77,11 @@ RUN python3 -m pip install -r requirements.txt # Add component files into working directory WORKDIR /var/teraflow COPY src/context/. context/ COPY src/device/. device/ COPY src/monitoring/. monitoring/ COPY src/context/__init__.py context/__init__.py COPY src/context/client/. context/client/ COPY src/monitoring/__init__.py monitoring/__init__.py COPY src/monitoring/client/. monitoring/client/ # Start the service ENTRYPOINT ["python", "-m", "device.service"] src/device/requirements.in +7 −7 Original line number Diff line number Diff line Loading @@ -12,30 +12,30 @@ # See the License for the specific language governing permissions and # limitations under the License. anytree==2.8.0 APScheduler==3.10.1 bitarray==2.8.* cryptography==36.0.2 #fastcache==1.1.0 ipaddress Jinja2==3.0.3 libyang==2.8.0 macaddress ncclient==0.6.13 p4runtime==1.3.0 pandas==1.5.* paramiko==2.9.2 pyang==2.6.* git+https://github.com/robshakir/pyangbind.git python-json-logger==2.0.2 #pytz==2021.3 #redis==4.1.2 requests==2.27.1 requests-mock==1.9.3 xmltodict==0.12.0 tabulate ipaddress macaddress yattag pyang==2.6.* git+https://github.com/robshakir/pyangbind.git websockets==10.4 xmltodict==0.12.0 yattag # pip's dependency resolver does not take into account installed packages. # p4runtime does not specify the version of grpcio/protobuf it needs, so it tries to install latest one Loading src/device/service/drivers/gnmi_openconfig/handlers/Component.py +2 −2 Original line number Diff line number Diff line Loading @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. import json, logging # libyang import json, logging, re # libyang from typing import Any, Dict, List, Tuple from common.proto.kpi_sample_types_pb2 import KpiSampleType from ._Handler import _Handler Loading Loading @@ -55,7 +55,7 @@ class ComponentHandler(_Handler): # TODO: improve mapping between interface name and component name # By now, computed by time for the sake of saving time for the Hackfest. interface_name = component_name.lower().replace('-port', '') interface_name = re.sub(r'\-[pP][oO][rR][tT]', '', component_name) endpoint = {'uuid': interface_name, 'type': '-'} endpoint['sample_types'] = { Loading src/device/service/drivers/gnmi_openconfig/handlers/NetworkInstance.py +7 −10 Original line number Diff line number Diff line Loading @@ -134,18 +134,15 @@ class NetworkInstanceHandler(_Handler): for static_route in static_routes: static_route_prefix = static_route['prefix'] next_hops = static_route.get('next-hops', {}).get('next-hop', []) _next_hops = [ { 'index' : next_hop['index'], 'gateway': next_hop['config']['next-hop'], next_hops = { next_hop['index'] : { 'next_hop': next_hop['config']['next-hop'], 'metric' : next_hop['config']['metric'], } for next_hop in next_hops ] _next_hops = sorted(_next_hops, key=operator.itemgetter('index')) for next_hop in static_route.get('next-hops', {}).get('next-hop', []) } _static_route = {'prefix': static_route_prefix, 'next_hops': _next_hops} _static_route = {'prefix': static_route_prefix, 'next_hops': next_hops} entry_static_route_key = '{:s}/static_routes[{:s}]'.format( entry_protocol_key, static_route_prefix ) Loading src/device/service/drivers/gnmi_openconfig/handlers/NetworkInstanceStaticRoute.py +3 −3 Original line number Diff line number Diff line Loading @@ -40,7 +40,7 @@ class NetworkInstanceStaticRouteHandler(_Handler): return str_path, str_data next_hop = get_str(resource_value, 'next_hop' ) # '172.0.0.1' next_hop_index = get_int(resource_value, 'next_hop_index', 0) # 0 next_hop_index = get_str(resource_value, 'next_hop_index') # AUTO_1_172-0-0-1 PATH_TMPL = '/network-instances/network-instance[name={:s}]/protocols/protocol[identifier={:s}][name={:s}]' str_path = PATH_TMPL.format(ni_name, identifier, name) Loading Loading @@ -74,7 +74,7 @@ class NetworkInstanceStaticRouteHandler(_Handler): yang_ni_pr_sr.create_path('config/prefix', prefix) yang_ni_pr_sr_nhs : libyang.DContainer = yang_ni_pr_sr.create_path('next-hops') yang_ni_pr_sr_nh_path = 'next-hop[index="{:d}"]'.format(next_hop_index) yang_ni_pr_sr_nh_path = 'next-hop[index="{:s}"]'.format(next_hop_index) yang_ni_pr_sr_nh : libyang.DContainer = yang_ni_pr_sr_nhs.create_path(yang_ni_pr_sr_nh_path) yang_ni_pr_sr_nh.create_path('config/index', next_hop_index) yang_ni_pr_sr_nh.create_path('config/next-hop', next_hop) Loading Loading
src/device/Dockerfile +19 −2 Original line number Diff line number Diff line Loading @@ -53,6 +53,21 @@ RUN python3 -m grpc_tools.protoc -I=. --python_out=. --grpc_python_out=. *.proto RUN rm *.proto RUN find . -type f -exec sed -i -E 's/(import\ .*)_pb2/from . \1_pb2/g' {} \; # Download, build and install libyang. Note that APT package is outdated # - Ref: https://github.com/CESNET/libyang # - Ref: https://github.com/CESNET/libyang-python/ RUN apt-get --yes --quiet --quiet update && \ apt-get --yes --quiet --quiet install build-essential cmake libpcre2-dev python3-dev python3-cffi && \ rm -rf /var/lib/apt/lists/* RUN mkdir -p /var/libyang RUN git clone https://github.com/CESNET/libyang.git /var/libyang RUN mkdir -p /var/libyang/build WORKDIR /var/libyang/build RUN cmake -D CMAKE_BUILD_TYPE:String="Release" .. RUN make RUN make install RUN ldconfig # Create component sub-folders, get specific Python packages RUN mkdir -p /var/teraflow/device WORKDIR /var/teraflow/device Loading @@ -62,9 +77,11 @@ RUN python3 -m pip install -r requirements.txt # Add component files into working directory WORKDIR /var/teraflow COPY src/context/. context/ COPY src/device/. device/ COPY src/monitoring/. monitoring/ COPY src/context/__init__.py context/__init__.py COPY src/context/client/. context/client/ COPY src/monitoring/__init__.py monitoring/__init__.py COPY src/monitoring/client/. monitoring/client/ # Start the service ENTRYPOINT ["python", "-m", "device.service"]
src/device/requirements.in +7 −7 Original line number Diff line number Diff line Loading @@ -12,30 +12,30 @@ # See the License for the specific language governing permissions and # limitations under the License. anytree==2.8.0 APScheduler==3.10.1 bitarray==2.8.* cryptography==36.0.2 #fastcache==1.1.0 ipaddress Jinja2==3.0.3 libyang==2.8.0 macaddress ncclient==0.6.13 p4runtime==1.3.0 pandas==1.5.* paramiko==2.9.2 pyang==2.6.* git+https://github.com/robshakir/pyangbind.git python-json-logger==2.0.2 #pytz==2021.3 #redis==4.1.2 requests==2.27.1 requests-mock==1.9.3 xmltodict==0.12.0 tabulate ipaddress macaddress yattag pyang==2.6.* git+https://github.com/robshakir/pyangbind.git websockets==10.4 xmltodict==0.12.0 yattag # pip's dependency resolver does not take into account installed packages. # p4runtime does not specify the version of grpcio/protobuf it needs, so it tries to install latest one Loading
src/device/service/drivers/gnmi_openconfig/handlers/Component.py +2 −2 Original line number Diff line number Diff line Loading @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. import json, logging # libyang import json, logging, re # libyang from typing import Any, Dict, List, Tuple from common.proto.kpi_sample_types_pb2 import KpiSampleType from ._Handler import _Handler Loading Loading @@ -55,7 +55,7 @@ class ComponentHandler(_Handler): # TODO: improve mapping between interface name and component name # By now, computed by time for the sake of saving time for the Hackfest. interface_name = component_name.lower().replace('-port', '') interface_name = re.sub(r'\-[pP][oO][rR][tT]', '', component_name) endpoint = {'uuid': interface_name, 'type': '-'} endpoint['sample_types'] = { Loading
src/device/service/drivers/gnmi_openconfig/handlers/NetworkInstance.py +7 −10 Original line number Diff line number Diff line Loading @@ -134,18 +134,15 @@ class NetworkInstanceHandler(_Handler): for static_route in static_routes: static_route_prefix = static_route['prefix'] next_hops = static_route.get('next-hops', {}).get('next-hop', []) _next_hops = [ { 'index' : next_hop['index'], 'gateway': next_hop['config']['next-hop'], next_hops = { next_hop['index'] : { 'next_hop': next_hop['config']['next-hop'], 'metric' : next_hop['config']['metric'], } for next_hop in next_hops ] _next_hops = sorted(_next_hops, key=operator.itemgetter('index')) for next_hop in static_route.get('next-hops', {}).get('next-hop', []) } _static_route = {'prefix': static_route_prefix, 'next_hops': _next_hops} _static_route = {'prefix': static_route_prefix, 'next_hops': next_hops} entry_static_route_key = '{:s}/static_routes[{:s}]'.format( entry_protocol_key, static_route_prefix ) Loading
src/device/service/drivers/gnmi_openconfig/handlers/NetworkInstanceStaticRoute.py +3 −3 Original line number Diff line number Diff line Loading @@ -40,7 +40,7 @@ class NetworkInstanceStaticRouteHandler(_Handler): return str_path, str_data next_hop = get_str(resource_value, 'next_hop' ) # '172.0.0.1' next_hop_index = get_int(resource_value, 'next_hop_index', 0) # 0 next_hop_index = get_str(resource_value, 'next_hop_index') # AUTO_1_172-0-0-1 PATH_TMPL = '/network-instances/network-instance[name={:s}]/protocols/protocol[identifier={:s}][name={:s}]' str_path = PATH_TMPL.format(ni_name, identifier, name) Loading Loading @@ -74,7 +74,7 @@ class NetworkInstanceStaticRouteHandler(_Handler): yang_ni_pr_sr.create_path('config/prefix', prefix) yang_ni_pr_sr_nhs : libyang.DContainer = yang_ni_pr_sr.create_path('next-hops') yang_ni_pr_sr_nh_path = 'next-hop[index="{:d}"]'.format(next_hop_index) yang_ni_pr_sr_nh_path = 'next-hop[index="{:s}"]'.format(next_hop_index) yang_ni_pr_sr_nh : libyang.DContainer = yang_ni_pr_sr_nhs.create_path(yang_ni_pr_sr_nh_path) yang_ni_pr_sr_nh.create_path('config/index', next_hop_index) yang_ni_pr_sr_nh.create_path('config/next-hop', next_hop) Loading