Efficient Network Automation with gRPC and NETCONF
Sachin Verma
Network Automation Developer | AAP (Ansible) & Python Developer | Cisco NSO Specialist | NetDevOps | CCNA Certified | Oracle & Azure Certified Cloud Associate | Director @ Morgan Stanley | Ex- Capgemini & Airtel
gRPC (gRPC Remote Procedure Call) and NETCONF (Network Configuration Protocol) are both technologies designed to facilitate communication and automation in network environments, but they serve different purposes and have distinct characteristics.
Let's compare gRPC and NETCONF:
gRPC (gRPC Remote Procedure Call):
NETCONF (Network Configuration Protocol):
领英推荐
Distinctions:
So, what about the example of interacting with routers using these protocols ??
import grpc
from your_proto_generated_module import your_proto_pb2, your_proto_pb2_grpc
def get_router_version():
with grpc.insecure_channel('router_ip:50051') as channel:
stub = your_proto_pb2_grpc.YourServiceStub(channel)
request = your_proto_pb2.YourRequest()
response = stub.GetRouterVersion(request)
return response.version_info
if __name__ == '__main__':
router_version = get_router_version()
print(f"Router Version Information:\n{router_version}")
from ncclient import manager
def get_router_version():
with manager.connect(
host='router_ip',
port=830,
username='your_username',
password='your_password',
hostkey_verify=False, # Disable host key verification for simplicity, use it cautiously in production
device_params={'name': 'your_device_type'}, # Replace 'your_device_type' with your router's type (e.g., 'iosxr', 'junos')
) as device:
# Specify the NETCONF filter for the 'show version' command
filter_str = '''
<filter>
<show xmlns="https://www.cisco.com/nxos:1.0">
<version/>
</show>
</filter>
'''
# Retrieve the 'show version' information
result = device.get(('subtree', filter_str))
return result.data_xml
if __name__ == '__main__':
router_version = get_router_version()
print(f"Router Version Information:\n{router_version}")
In summary, both gRPC and NETCONF are communication and automation tools. However, gRPC is a versatile RPC framework that can be used in different domains, including microservices. On the other hand, NETCONF is designed exclusively for configuring and managing network devices. Choosing between them depends on the specific use case requirements. If the use case requires general communication between services, gRPC is the better choice. If automation of networking tasks is needed, then NETCONF is the way to go.