Пример #1
0
    def test_gnmi_service_subscribe_multiple(self):
        # Create interface and BGP configurations
        bgp = build_bgp_config()
        bgp.yfilter = YFilter.replace

        ifc = build_int_config()
        ifc.yfilter = YFilter.replace
        reply = self.gs.set(self.provider, [bgp, ifc])
        self.assertTrue(reply)

        bgp_filter = openconfig_bgp.Bgp()
        bgp_subscription = gNMISubscription()
        bgp_subscription.entity = bgp_filter

        int_filter = openconfig_interfaces.Interfaces()
        int_subscription = gNMISubscription()
        int_subscription.entity = int_filter

        self.gs.subscribe(self.provider, [int_subscription, bgp_subscription],
                          10, "ONCE", "JSON_IETF",
                          gnmi_subscribe_multiples_callback)

        # Delete BGP configuration
        bgp.yfilter = YFilter.delete
        ifc.yfilter = YFilter.delete
        reply = self.gs.set(self.provider, [bgp, ifc])
        self.assertTrue(reply)
Пример #2
0
def run_test(device, repo_path, mode, ca, call_back):

    # Create gNMI Service Provider and gNMI Service
    provider = gNMIServiceProvider(Repository(repo_path),
                                   address=device.hostname,
                                   port=device.port,
                                   username=device.username,
                                   password=device.password,
                                   server_certificate=ca)
    gs = gNMIService()
    """Build entity for interface operational data"""
    ifc_oper_filter = ifoper.InterfaceProperties()
    dn = ifoper.InterfaceProperties.DataNodes.DataNode()
    dn.data_node_name = '"0/RP0/CPU0"'
    ifc_oper_filter.data_nodes.data_node.append(dn)

    lview = ifoper.InterfaceProperties.DataNodes.DataNode.Locationviews.Locationview(
    )
    lview.locationview_name = '"0/RP0/CPU0"'
    dn.locationviews.locationview.append(lview)

    ifc = ifoper.InterfaceProperties.DataNodes.DataNode.Locationviews.Locationview.Interfaces.Interface(
    )
    ifc.interface_name = '"Loopback0"'
    ifc.state = YFilter.read
    lview.interfaces.interface.append(ifc)
    """Build subscription"""
    subscription = gNMISubscription()
    subscription.entity = ifc_oper_filter
    subscription.suppress_redundant = False
    subscription.subscription_mode = "SAMPLE"
    subscription.sample_interval = 3 * 1000000000
    subscription.heartbeat_interval = 30 * 1000000000
    """Send subscribe request"""
    gs.subscribe(provider, subscription, 10, mode, "PROTO", call_back)
def subscribe(args):
    func = args[0]
    device = args[1]
    mode = args[2]

    gnmi = gNMIService()
    repository = Repository(get_local_repo_dir())
    provider = gNMIServiceProvider(repo=repository,
                                   address=device.hostname,
                                   port=device.port,
                                   username=device.username,
                                   password=device.password)

    build_int_config(provider)

    inf = openconfig_interfaces.Interfaces()
    i = openconfig_interfaces.Interfaces.Interface()
    inf.interface.append(i)

    int_subscription = gNMISubscription()
    int_subscription.entity = inf
    int_subscription.subscription_mode = "SAMPLE"
    int_subscription.sample_interval = 20 * 1000000000
    int_subscription.suppress_redundant = False
    int_subscription.heartbeat_interval = 100 * 1000000000

    gnmi.subscribe(provider, int_subscription, 10, mode, 'JSON_IETF', func)
Пример #4
0
    def test_gnmi_service_subscribe_poll(self):
        # Create BGP configuration
        bgp = build_bgp_config()
        bgp.yfilter = YFilter.replace
        reply = self.gs.set(self.provider, bgp)

        subscription = gNMISubscription()
        bgp_filter = openconfig_bgp.Bgp()
        subscription.entity = bgp_filter

        self.gs.subscribe(self.provider, subscription, 10, "POLL", "JSON_IETF", gnmi_subscribe_callback)

        # Delete BGP configuration
        bgp.yfilter = YFilter.delete
        reply = self.gs.set(self.provider, bgp)
Пример #5
0
    def test_gnmi_service_subscribe_stream(self):
        # Create BGP configuration
        bgp = build_bgp_config()
        bgp.yfilter = YFilter.replace
        reply = self.gs.set(self.provider, bgp)

        subscription = gNMISubscription()
        bgp_filter = openconfig_bgp.Bgp()
        subscription.subscription_mode = "SAMPLE"
        subscription.sample_interval = 2 * 1000000000
        subscription.suppress_redundant = False
        subscription.heartbeat_interval = 8 * 1000000000
        subscription.entity = bgp_filter

        self.gs.subscribe(self.provider, subscription, 10, "STREAM", "JSON_IETF", gnmi_subscribe_callback)

        # Delete BGP configuration
        bgp.yfilter = YFilter.delete
        reply = self.gs.set(self.provider, bgp)
Пример #6
0
    def test_gnmi_service_subscribe_once(self):
        # Create BGP configuration
        bgp = build_bgp_config()
        bgp.yfilter = YFilter.replace
        reply = self.gs.set(self.provider, bgp)
 
        subscription = gNMISubscription()
        bgp_filter = openconfig_bgp.Bgp()
        subscription.subscription_mode = "ON_CHANGE"
        subscription.sample_interval = 10 * 1000000000
        subscription.suppress_redundant = True
        subscription.heartbeat_interval = 100 * 1000000000
        subscription.entity = bgp_filter
 
        self.gs.subscribe(self.provider, subscription, 10, "ONCE", "JSON_IETF", gnmi_subscribe_callback);
 
        # Delete BGP configuration
        bgp.yfilter = YFilter.delete
        reply = self.gs.set(self.provider, bgp)
Пример #7
0
def subscribe(func):
    gnmi = gNMIService()

    try:
        try:
            #Running on dev1 environment of tesuto cloud setup for Nanog75
            repository = Repository('/home/tesuto/yang/')
        except:
            #Running in a docker container started off image akshshar/nanog75-telemetry
            repository = Repository('/root/yang/')
            raise
    except Exception as e:
        print(
            "Failed to import yang models, check repository path,  aborting...."
        )
        sys.exit(1)

    provider = gNMIServiceProvider(repo=repository,
                                   address='100.96.0.14',
                                   port=57777,
                                   username='******',
                                   password='******')

    # The below will create a telemetry subscription path 'openconfig-interfaces:interfaces/interface'
    interfaces = openconfig_interfaces.Interfaces()
    interface = openconfig_interfaces.Interfaces.Interface()
    interfaces.interface.append(interface)

    network_instances = openconfig_network_instance.NetworkInstances()

    subscription = gNMISubscription()
    subscription.entity = interfaces  #network_instances

    subscription.subscription_mode = "SAMPLE"
    subscription.sample_interval = 10 * 1000000000
    subscription.suppress_redundant = False
    subscription.heartbeat_interval = 100 * 1000000000

    # Subscribe for updates in STREAM mode.
    var = gnmi.subscribe(provider, subscription, 10, "STREAM", "PROTO", func)
def run_test(device, mode, ca, call_back):

    # Create gNMI Service Provider and gNMI Service
    repo = Repository("/home/ygorelik/ydk-gen/scripts/samples/repository/192.168.122.107")
    provider = gNMIServiceProvider(repo, address=device.hostname,
                                      port=device.port,
                                      username=device.username,
                                      password=device.password,
                                      server_certificate=ca)
    gs = gNMIService()

    """Build entity for interface operational data"""
    ifc_oper_filter = ifoper.InterfaceProperties()
    dn = ifoper.InterfaceProperties.DataNodes.DataNode()
    dn.data_node_name = '"0/RP0/CPU0"'
    ifc_oper_filter.data_nodes.data_node.append(dn)

    lview = ifoper.InterfaceProperties.DataNodes.DataNode.Locationviews.Locationview()
    lview.locationview_name = '"0/RP0/CPU0"'
    dn.locationviews.locationview.append(lview)
    
    ifc = ifoper.InterfaceProperties.DataNodes.DataNode.Locationviews.Locationview.Interfaces.Interface()
    ifc.interface_name = '"Loopback10"'
    ifc.state = YFilter.read
    lview.interfaces.interface.append(ifc)

    """Build subscription"""
    subscription = gNMISubscription()
    subscription.entity = ifc_oper_filter
    subscription.suppress_redundant = False;
    subscription.subscription_mode = "SAMPLE";
    subscription.sample_interval    = 3 * 1000000000;
    subscription.heartbeat_interval = 30 * 1000000000;

    """Send sunscribe request"""
    gs.subscribe(provider, subscription, 10, mode, "PROTO", call_back);