def config_rsvp(rsvp):
    """Add config data to rsvp object."""
    # RSVP interface gig0/0/0/0
    interface = rsvp.interfaces.Interface()
    interface.name = "GigabitEthernet0/0/0/0"
    interface.enable = Empty()
    interface.bandwidth.rdm.bc0_bandwidth = 100
    interface.bandwidth.rdm.bc1_bandwidth = 25
    interface.bandwidth.rdm.rdm_keyword = xr_ip_rsvp_cfg.RsvpRdmEnum.RDM
    interface.bandwidth.rdm.bc0_keyword = xr_ip_rsvp_cfg.RsvpBc0Enum.NOT_SPECIFIED
    interface.bandwidth.rdm.bc1_keyword = xr_ip_rsvp_cfg.RsvpBc1Enum.SUB_POOL
    interface.bandwidth.rdm.bandwidth_mode = xr_ip_rsvp_cfg.RsvpBwCfgEnum.PERCENTAGE
    rsvp.interfaces.interface.append(interface)

    # RSVP interface gig0/0/0/1
    interface = rsvp.interfaces.Interface()
    interface.name = "GigabitEthernet0/0/0/1"
    interface.enable = Empty()
    interface.bandwidth.rdm.bc0_bandwidth = 100
    interface.bandwidth.rdm.bc1_bandwidth = 25
    interface.bandwidth.rdm.rdm_keyword = xr_ip_rsvp_cfg.RsvpRdmEnum.RDM
    interface.bandwidth.rdm.bc0_keyword = xr_ip_rsvp_cfg.RsvpBc0Enum.NOT_SPECIFIED
    interface.bandwidth.rdm.bc1_keyword = xr_ip_rsvp_cfg.RsvpBc1Enum.SUB_POOL
    interface.bandwidth.rdm.bandwidth_mode = xr_ip_rsvp_cfg.RsvpBwCfgEnum.PERCENTAGE
    rsvp.interfaces.interface.append(interface)
Esempio n. 2
0
 def multicast(obj, node, l3intlist):
     obj.ip.multicast_routing = Cisco_IOS_XE_native.Native.Ip.MulticastRouting(
     )
     obj.ip.multicast_routing.distributed = Empty()
     obj.ip.multicast_routing._is_presence = True
     # Sort the l3intlist so they are grouped by interface type
     l3intlist.sort(key=str.lower)
     # Make the l3intlist all lowercase
     lowerl3intlist = map(lambda x: x.lower(), l3intlist)
     # Add PIM Sparse to all interfaces of l3intlist
     for ints in lowerl3intlist:
         interfacetype = ''.join(i for i in ints if not i.isdigit())
         intconfiglist = None
         intconfiglist = intobjectselector(interfacetype)
         intconfiglist.name = nameSelector(ints)
         intconfiglist.ip.pim.sparse_mode = Cisco_IOS_XE_native.Native.Interface.Loopback.Ip.Pim.SparseModeEnum.sparse_mode
         getattr(obj.interface, interfacetype).append(intconfiglist)
         #obj.interface.interfacetype.append(intconfiglist)
     #IF DEVICE IS NOT RP - SET AUTORP LISTENER and IP PIM SPARSE-MODE ON L3 INTERFACES AND SETUP LOOP1 FIRST!!!
     if node.rp == False:
         obj.ip.pim.autorp = Cisco_IOS_XE_native.Native.Ip.Pim.Autorp()
         obj.ip.pim.autorp.listener = Empty()
         obj.ip.pim.register_source = "Loopback0"
     else:
         rpannounceintlist = obj.Ip.Pim.SendRpAnnounce.Interface_List()
         rpannounceintlist.if_name = "Loopback1"
         rpannounceintlist.scope.pkt_ttl = 30
         obj.ip.pim.send_rp_announce.interface_list.append(
             rpannounceintlist)
         obj.ip.msdp.originator_id = "Loopback0"
         obj.ip.msdp.peer.addr = node.msdp_peer
         obj.ip.msdp.peer.connect_source = "Loopback0"
         obj.ip.pim.send_rp_discovery.scope = 30
     return obj
    def test_copy_config_rpc(self):
        rpc = ietf_netconf.CopyConfig()
        rpc.input.target.candidate = Empty()
        rpc.input.source.running = Empty()

        reply = self.es.execute_rpc(self.ncc, rpc)
        self.assertIsNone(reply)
def config_grpc(grpc):
    """Add config data to grpc object."""
    grpc.enable = Empty()
    grpc.address_family = "ipv6"
    grpc.max_request_per_user = 8
    grpc.max_request_total = 32
    grpc.tls.enable = Empty()
def config_telemetry_model_driven(telemetry_model_driven):
    """Add config data to telemetry_model_driven object."""
    # sensor group
    sensor_group = telemetry_model_driven.sensor_groups.SensorGroup()
    sensor_group.sensor_group_identifier = "SGROUP1"
    sensor_group.enable = Empty()
    sensor_path = sensor_group.sensor_paths.SensorPath()
    sensor_path.telemetry_sensor_path = "Cisco-IOS-XR-infra-statsd-oper:infra-statistics/interfaces/interface/latest/generic-counters"
    sensor_group.sensor_paths.sensor_path.append(sensor_path)
    telemetry_model_driven.sensor_groups.sensor_group.append(sensor_group)
    sensor_group = telemetry_model_driven.sensor_groups.SensorGroup()
    sensor_group.sensor_group_identifier = "SGROUP2"
    sensor_group.enable = Empty()
    sensor_path = sensor_group.sensor_paths.SensorPath()
    sensor_path.telemetry_sensor_path = "Cisco-IOS-XR-nto-misc-oper:memory-summary/nodes/node/summary"
    sensor_group.sensor_paths.sensor_path.append(sensor_path)
    telemetry_model_driven.sensor_groups.sensor_group.append(sensor_group)

    # subscription
    subscription = telemetry_model_driven.subscriptions.Subscription()
    subscription.subscription_identifier = "SUB1"
    sensor_profile = subscription.sensor_profiles.SensorProfile()
    sensor_profile.sensorgroupid = "SGROUP1"
    sensor_profile.sample_interval = 30000
    subscription.sensor_profiles.sensor_profile.append(sensor_profile)
    sensor_profile = subscription.sensor_profiles.SensorProfile()
    sensor_profile.sensorgroupid = "SGROUP2"
    sensor_profile.sample_interval = 8000
    subscription.sensor_profiles.sensor_profile.append(sensor_profile)
    telemetry_model_driven.subscriptions.subscription.append(subscription)
Esempio n. 6
0
def config_ospf(ospf):
    """Add config data to ospf object."""
    # OSPF process
    process = ospf.processes.Process()
    process.process_name = "DEFAULT"
    process.default_vrf.router_id = "172.16.255.1"

    # Area 0
    area_area_id = process.default_vrf.area_addresses.AreaAreaId()
    area_area_id.area_id = 0
    area_area_id.running = Empty()

    # loopback interface passive
    name_scope = area_area_id.name_scopes.NameScope()
    name_scope.interface_name = "Loopback0"
    name_scope.running = Empty()
    name_scope.passive = True
    area_area_id.name_scopes.name_scope.append(name_scope)

    # gi0/0/0/0 interface
    name_scope = area_area_id.name_scopes.NameScope()
    name_scope.interface_name = "GigabitEthernet0/0/0/0"
    name_scope.running = Empty()
    name_scope.network_type = xr_ipv4_ospf_cfg.OspfNetworkEnum.point_to_point
    area_area_id.name_scopes.name_scope.append(name_scope)

    # append area/process config
    process.default_vrf.area_addresses.area_area_id.append(area_area_id)
    ospf.processes.process.append(process)
Esempio n. 7
0
def configure_bgp_vrf(bgp, local_as, vrf_name, route_distinguisher):
    """Add config data to bgp object."""
    # global configuration
    instance = bgp.Instance()
    instance.instance_name = "default"
    instance_as = instance.InstanceAs()
    instance_as.as_ = 0
    four_byte_as = instance_as.FourByteAs()
    four_byte_as.as_ = local_as
    four_byte_as.bgp_running = Empty()

    # vrf configuration
    vrf = four_byte_as.vrfs.Vrf()
    vrf.vrf_name = vrf_name
    vrf.vrf_global.exists = Empty()
    vrf.vrf_global.route_distinguisher.type = xr_ipv4_bgp_cfg.BgpRouteDistinguisher.as_
    as_, as_index = route_distinguisher.split(':')
    vrf.vrf_global.route_distinguisher.as_ = int(as_)
    vrf.vrf_global.route_distinguisher.as_xx = 0
    vrf.vrf_global.route_distinguisher.as_index = int(as_index)
    vrf_global_af = vrf.vrf_global.vrf_global_afs.VrfGlobalAf()
    vrf_global_af.af_name = xr_ipv4_bgp_datatypes.BgpAddressFamily.ipv4_unicast
    vrf_global_af.enable = Empty()
    vrf_global_af.connected_routes = vrf_global_af.ConnectedRoutes()
    vrf_global_af.connected_routes.default_metric = 10
    vrf.vrf_global.vrf_global_afs.vrf_global_af.append(vrf_global_af)
    four_byte_as.vrfs.vrf.append(vrf)

    # append configuration objects
    instance_as.four_byte_as.append(four_byte_as)
    instance.instance_as.append(instance_as)
    bgp.instance.append(instance)
Esempio n. 8
0
def configure_bgp_neighbor(bgp, local_as, neighbor_address, remote_as):
    """Add config data to bgp object."""
    # global configuration
    instance = bgp.Instance()
    instance.instance_name = "default"
    instance_as = instance.InstanceAs()
    instance_as.as_ = 0
    four_byte_as = instance_as.FourByteAs()
    four_byte_as.as_ = local_as
    four_byte_as.bgp_running = Empty()
    global_af = four_byte_as.default_vrf.global_.global_afs.GlobalAf()
    global_af.af_name = xr_ipv4_bgp_datatypes.BgpAddressFamily.vpnv4_unicast
    global_af.enable = Empty()
    four_byte_as.default_vrf.global_.global_afs.global_af.append(global_af)

    # configure BGP neighbor
    neighbor = four_byte_as.default_vrf.bgp_entity.neighbors.Neighbor()
    neighbor.neighbor_address = neighbor_address
    neighbor.remote_as.as_xx = 0
    neighbor.remote_as.as_yy = remote_as
    neighbor.update_source_interface = "Loopback0"
    neighbor_af = neighbor.neighbor_afs.NeighborAf()
    neighbor_af.af_name = xr_ipv4_bgp_datatypes.BgpAddressFamily.vpnv4_unicast
    neighbor_af.activate = Empty()
    neighbor.neighbor_afs.neighbor_af.append(neighbor_af)
    four_byte_as.default_vrf.bgp_entity.neighbors.neighbor.append(neighbor)

    # append configuration objects
    instance_as.four_byte_as.append(four_byte_as)
    instance.instance_as.append(instance_as)
    bgp.instance.append(instance)
Esempio n. 9
0
def config_ospfv3(ospfv3):
    """Add config data to ospfv3 object."""
    # OSPFv3 process
    process = ospfv3.processes.Process()
    process.process_name = "DEFAULT"
    process.default_vrf.router_id = "172.16.255.1"
    process.enable = Empty()

    # Area 0
    area_area_id = process.default_vrf.area_addresses.AreaAreaId()
    area_area_id.area_id = 0
    area_area_id.enable = Empty()

    # loopback interface passive
    interface = area_area_id.interfaces.Interface()
    interface.interface_name = "Loopback0"
    interface.enable = Empty()
    interface.passive = True
    area_area_id.interfaces.interface.append(interface)

    # gi0/0/0/0 interface
    interface = area_area_id.interfaces.Interface()
    interface.interface_name = "GigabitEthernet0/0/0/0"
    interface.enable = Empty()
    interface.network = xr_ipv6_ospfv3_cfg.Ospfv3Network.point_to_point
    area_area_id.interfaces.interface.append(interface)

    # append area/process config
    process.default_vrf.area_addresses.area_area_id.append(area_area_id)
    ospfv3.processes.process.append(process)
Esempio n. 10
0
def config_ospf(ospf):
    """Add config data to ospf object."""
    # OSPF process
    process = ospf.processes.Process()
    process.process_name = "udx"
    process.start = Empty()

    # Area 0
    area_area_id = process.default_vrf.area_addresses.AreaAreaId()
    area_area_id.area_id = 0
    area_area_id.running = Empty()

    # gi0/0/0/0 interface
    name_scope = area_area_id.name_scopes.NameScope()
    name_scope.interface_name = "GigabitEthernet0/0/0/0"
    name_scope.running = Empty()
    area_area_id.name_scopes.name_scope.append(name_scope)

    # gi0/0/0/1 interface
    name_scope = area_area_id.name_scopes.NameScope()
    name_scope.interface_name = "GigabitEthernet0/0/0/1"
    name_scope.running = Empty()
    area_area_id.name_scopes.name_scope.append(name_scope)

    # gi0/0/0/2 interface
    name_scope = area_area_id.name_scopes.NameScope()
    name_scope.interface_name = "GigabitEthernet0/0/0/2"
    name_scope.running = Empty()
    area_area_id.name_scopes.name_scope.append(name_scope)

    # append area/process config
    process.default_vrf.area_addresses.area_area_id.append(area_area_id)
    ospf.processes.process.append(process)
Esempio n. 11
0
    def test_edit_config_rpc(self):
        runner = ysanity.Runner()
        runner.ydktest_sanity_one.number = 1
        runner.ydktest_sanity_one.name = 'runner:one:name'

        runner_xml = self.cs.encode(self.csp, runner)
        filter_xml = self.cs.encode(self.csp, ysanity.Runner())

        # Edit Config
        edit_rpc = ietf_netconf.EditConfig()
        edit_rpc.input.target.candidate = Empty()
        edit_rpc.input.config = runner_xml
        reply = self.es.execute_rpc(self.ncc, edit_rpc)
        self.assertIsNone(reply)

        # Get Config
        get_config_rpc = ietf_netconf.GetConfig()
        get_config_rpc.input.source.candidate = Empty()
        get_config_rpc.input.filter = filter_xml
        reply = self.es.execute_rpc(self.ncc, get_config_rpc, runner)
        self.assertIsNotNone(reply)
        self.assertEqual(reply, runner)

        # Commit
        commit_rpc = ietf_netconf.Commit()
        reply = self.es.execute_rpc(self.ncc, commit_rpc)
        self.assertIsNone(reply)

        # Get
        get_rpc = ietf_netconf.Get()
        get_rpc.input.filter = filter_xml
        reply = self.es.execute_rpc(self.ncc, get_rpc, runner)
        self.assertIsNotNone(reply)
        self.assertEqual(reply, runner)
Esempio n. 12
0
def config_rsvp(rsvp):
    """Add config data to rsvp object."""
    # RSVP interface gig0/0/0/0
    interface = rsvp.interfaces.Interface()
    interface.name = "GigabitEthernet0/0/0/0"
    interface.enable = Empty()
    interface.bandwidth.rdm.bc0_bandwidth = 100
    interface.bandwidth.rdm.bc1_bandwidth = 25
    interface.bandwidth.rdm.rdm_keyword = xr_ip_rsvp_cfg.RsvpRdm.rdm
    interface.bandwidth.rdm.bc0_keyword = xr_ip_rsvp_cfg.RsvpBc0.not_specified
    interface.bandwidth.rdm.bc1_keyword = xr_ip_rsvp_cfg.RsvpBc1.sub_pool
    interface.bandwidth.rdm.bandwidth_mode = xr_ip_rsvp_cfg.RsvpBwCfg.percentage
    rsvp.interfaces.interface.append(interface)

    # RSVP interface gig0/0/0/1
    interface = rsvp.interfaces.Interface()
    interface.name = "GigabitEthernet0/0/0/1"
    interface.enable = Empty()
    interface.bandwidth.rdm.bc0_bandwidth = 100
    interface.bandwidth.rdm.bc1_bandwidth = 25
    interface.bandwidth.rdm.rdm_keyword = xr_ip_rsvp_cfg.RsvpRdm.rdm
    interface.bandwidth.rdm.bc0_keyword = xr_ip_rsvp_cfg.RsvpBc0.not_specified
    interface.bandwidth.rdm.bc1_keyword = xr_ip_rsvp_cfg.RsvpBc1.sub_pool
    interface.bandwidth.rdm.bandwidth_mode = xr_ip_rsvp_cfg.RsvpBwCfg.percentage
    rsvp.interfaces.interface.append(interface)
Esempio n. 13
0
def config_routing_policy(routing_policy):
    """Add config data to routing_policy object."""
    # configure as-path set
    bgp_defined_sets = routing_policy.defined_sets.bgp_defined_sets
    as_path_set = bgp_defined_sets.as_path_sets.AsPathSet()
    as_path_set.as_path_set_name = "AS-PATH-SET1"
    as_path_set.config.as_path_set_name = "AS-PATH-SET1"
    as_path_set.config.as_path_set_member.append("^65172")
    bgp_defined_sets.as_path_sets.as_path_set.append(as_path_set)

    # configure community set
    bgp_defined_sets = routing_policy.defined_sets.bgp_defined_sets
    community_set = bgp_defined_sets.community_sets.CommunitySet()
    community_set.community_set_name = "COMMUNITY-SET1"
    community_set.config.community_set_name = "COMMUNITY-SET1"
    community_set.config.community_member.append("ios-regex '^65172:17...$'")
    community_set.config.community_member.append("65172:16001")
    bgp_defined_sets.community_sets.community_set.append(community_set)

    # configure policy definition
    policy_definition = routing_policy.policy_definitions.PolicyDefinition()
    policy_definition.name = "POLICY2"
    policy_definition.config.name = "POLICY2"
    # community-set statement
    statement = policy_definition.statements.Statement()
    statement.name = "community-set1"
    statement.config.name = "community-set1"
    bgp_conditions = statement.conditions.bgp_conditions
    match_community_set = bgp_conditions.MatchCommunitySet()
    match_community_set.config.community_set = "COMMUNITY-SET1"
    match_set_options = oc_policy_types.MatchSetOptionsType.ALL
    match_community_set.config.match_set_options = match_set_options
    bgp_conditions.match_community_set = match_community_set
    statement.actions.config.accept_route = Empty()
    policy_definition.statements.statement.append(statement)
    # as-path-set statement
    statement = policy_definition.statements.Statement()
    statement.name = "as-path-set1"
    statement.config.name = "as-path-set1"
    bgp_conditions = statement.conditions.bgp_conditions
    match_as_path_set = bgp_conditions.MatchAsPathSet()
    match_as_path_set.config.as_path_set = "AS-PATH-SET1"
    match_set_options = oc_policy_types.MatchSetOptionsType.ANY
    match_as_path_set.config.match_set_options = match_set_options
    bgp_conditions.match_as_path_set = match_as_path_set
    statement.actions.bgp_actions.config.set_local_pref = 50
    statement.actions.config.accept_route = Empty()
    policy_definition.statements.statement.append(statement)
    # reject statement
    statement = policy_definition.statements.Statement()
    statement.name = "reject route"
    statement.config.name = "reject route"
    statement.actions.config.reject_route = Empty()
    policy_definition.statements.statement.append(statement)

    routing_policy.policy_definitions.policy_definition.append(
        policy_definition)
Esempio n. 14
0
def config_routing_policy(routing_policy):
    """Add config data to routing_policy object."""
    # configure prefix set
    prefix_set = routing_policy.defined_sets.prefix_sets.PrefixSet()
    prefix_set.prefix_set_name = "PREFIX-SET1"
    prefix_set.config.prefix_set_name = "PREFIX-SET1"
    prefix = prefix_set.prefixes.Prefix()
    prefix.ip_prefix = "10.0.0.0/16"
    prefix.masklength_range = "24..32"
    prefix.config.ip_prefix = "10.0.0.0/16"
    prefix.config.masklength_range = "24..32"
    prefix_set.prefixes.prefix.append(prefix)
    prefix = prefix_set.prefixes.Prefix()
    prefix.ip_prefix = "172.0.0.0/8"
    prefix.masklength_range = "16..32"
    prefix.config.ip_prefix = "172.0.0.0/8"
    prefix.config.masklength_range = "16..32"
    prefix_set.prefixes.prefix.append(prefix)
    routing_policy.defined_sets.prefix_sets.prefix_set.append(prefix_set)

    # configure community set
    bgp_defined_sets = routing_policy.defined_sets.bgp_defined_sets
    community_set = bgp_defined_sets.community_sets.CommunitySet()
    community_set.community_set_name = "COMMUNITY-SET2"
    community_set.config.community_set_name = "COMMUNITY-SET2"
    community_set.config.community_member.append("65172:17001")
    bgp_defined_sets.community_sets.community_set.append(community_set)

    # configure policy definition
    policy_definition = routing_policy.policy_definitions.PolicyDefinition()
    policy_definition.name = "POLICY3"
    policy_definition.config.name = "POLICY3"
    # prefix-set statement
    statement = policy_definition.statements.Statement()
    statement.name = "prefix-set1"
    statement.config.name = "prefix-set1"
    match_prefix_set = statement.conditions.MatchPrefixSet()
    match_prefix_set.config.prefix_set = "PREFIX-SET1"
    match_set_options = oc_policy_types.MatchSetOptionsRestrictedType.ANY
    match_prefix_set.config.match_set_options = match_set_options
    statement.conditions.match_prefix_set = match_prefix_set
    statement.actions.bgp_actions.config.set_local_pref = 1000
    set_community = statement.actions.bgp_actions.SetCommunity()
    set_community.reference.config.community_set_ref = "COMMUNITY-SET2"
    set_community.config.options = oc_bgp_policy.BgpSetCommunityOptionType.REPLACE
    statement.actions.bgp_actions.set_community = set_community
    statement.actions.config.accept_route = Empty()
    policy_definition.statements.statement.append(statement)
    # reject statement
    statement = policy_definition.statements.Statement()
    statement.name = "reject"
    statement.config.name = "reject"
    statement.actions.config.reject_route = Empty()
    policy_definition.statements.statement.append(statement)

    routing_policy.policy_definitions.policy_definition.append(
        policy_definition)
Esempio n. 15
0
    def test_parent_empty(self):
        runner = ysanity.Runner()
        runner.ytypes.enabled = Empty()
        runner.ytypes.built_in_t.emptee = Empty()

        self.crud.create(self.ncc, runner)

        runner_read = self.crud.read(self.ncc, ysanity.Runner())

        self.assertEqual(is_equal(runner_read, runner), True)
Esempio n. 16
0
    def test_execute_lock_unlock_rpc(self):
        lock_rpc = ietf_netconf.LockRpc()
        lock_rpc.input.target.candidate = Empty()
        op = self.executor.execute_rpc(self.ncc, lock_rpc)
        self.assertIn('ok', op)

        unlock_rpc = ietf_netconf.UnlockRpc()
        unlock_rpc.input.target.candidate = Empty()
        op = self.executor.execute_rpc(self.ncc, unlock_rpc)
        self.assertIn('ok', op)
Esempio n. 17
0
    def test_parent_empty(self):
        runner = Runner()
        runner.ytypes.enabled = Empty()
        runner.ytypes.built_in_t.emptee = Empty()

        self.crud.create(self.ncc, runner)

        runner_read = self.crud.read(self.ncc, Runner())

        self.assertEqual(runner, runner_read)
Esempio n. 18
0
    def test_lock_rpc(self):
        lock_rpc = ietf_netconf.Lock()
        lock_rpc.input.target.candidate = Empty()
        reply = self.es.execute_rpc(self.ncc, lock_rpc)
        self.assertIsNone(reply)

        unlock_rpc = ietf_netconf.Unlock()
        unlock_rpc.input.target.candidate = Empty()
        reply = self.es.execute_rpc(self.ncc, unlock_rpc)
        self.assertIsNone(reply)
Esempio n. 19
0
    def test_execute_lock_unlock_rpc(self):
        lock_rpc = LockRpc()
        lock_rpc.input.target.candidate = Empty()
        op = self.executor.execute_rpc(self.ncc, lock_rpc)
        self.assertEqual(None, op)

        unlock_rpc = UnlockRpc()
        unlock_rpc.input.target.candidate = Empty()
        op = self.executor.execute_rpc(self.ncc, unlock_rpc)
        self.assertEqual(None, op)
def config_telemetry_model_driven(telemetry_model_driven):
    """Add config data to telemetry_model_driven object."""
    # destination group
    destination_group = telemetry_model_driven.destination_groups.DestinationGroup(
    )
    destination_group.destination_id = "DGROUP1"
    ipv4_destination = destination_group.ipv4_destinations.Ipv4Destination()
    ipv4_destination.destination_port = 5432
    ipv4_destination.ipv4_address = "172.30.8.4"
    ipv4_destination.encoding = xr_telemetry_model_driven_cfg.EncodeType.self_describing_gpb
    protocol = ipv4_destination.Protocol()
    protocol.protocol = xr_telemetry_model_driven_cfg.ProtoType.grpc
    protocol.no_tls = 1
    ipv4_destination.protocol = protocol
    destination_group.ipv4_destinations.ipv4_destination.append(
        ipv4_destination)
    telemetry_model_driven.destination_groups.destination_group.append(
        destination_group)
    ipv4_destination = destination_group.ipv4_destinations.Ipv4Destination()
    ipv4_destination.destination_port = 9876
    ipv4_destination.ipv4_address = "172.30.8.11"
    ipv4_destination.encoding = xr_telemetry_model_driven_cfg.EncodeType.self_describing_gpb
    protocol = ipv4_destination.Protocol()
    protocol.protocol = xr_telemetry_model_driven_cfg.ProtoType.grpc
    protocol.no_tls = 1
    ipv4_destination.protocol = protocol
    destination_group.ipv4_destinations.ipv4_destination.append(
        ipv4_destination)
    telemetry_model_driven.destination_groups.destination_group.append(
        destination_group)

    # sensor group
    sensor_group = telemetry_model_driven.sensor_groups.SensorGroup()
    sensor_group.sensor_group_identifier = "SGROUP1"
    sensor_group.enable = Empty()
    sensor_path = sensor_group.sensor_paths.SensorPath()
    sensor_path.telemetry_sensor_path = "Cisco-IOS-XR-infra-statsd-oper:infra-statistics/interfaces/interface/latest/generic-counters"
    sensor_group.sensor_paths.sensor_path.append(sensor_path)
    telemetry_model_driven.sensor_groups.sensor_group.append(sensor_group)
    sensor_group = telemetry_model_driven.sensor_groups.SensorGroup()

    # subscription
    subscription = telemetry_model_driven.subscriptions.Subscription()
    subscription.subscription_identifier = "SUB1"
    sensor_profile = subscription.sensor_profiles.SensorProfile()
    sensor_profile.sensorgroupid = "SGROUP1"
    sensor_profile.sample_interval = 30000
    subscription.sensor_profiles.sensor_profile.append(sensor_profile)
    destination_profile = subscription.destination_profiles.DestinationProfile(
    )
    destination_profile.destination_id = "DGROUP1"
    destination_profile.enable = Empty()
    subscription.destination_profiles.destination_profile.append(
        destination_profile)
    telemetry_model_driven.subscriptions.subscription.append(subscription)
Esempio n. 21
0
    def test_execute_lock_unlock_rpc_fail(self):
        lock_rpc = ietf_netconf.LockRpc()
        lock_rpc.input.target.candidate = Empty()
        op = self.executor.execute_rpc(self.ncc, lock_rpc)
        self.assertIn('ok', op)

        unlock_rpc = ietf_netconf.UnlockRpc()
        unlock_rpc.input.target.running = Empty()
        try:
            op = self.executor.execute_rpc(self.ncc, unlock_rpc)
        except Exception as e:
            self.assertIsInstance(e, YPYError)
Esempio n. 22
0
    def test_unlock_rpc_fail(self):
        lock_rpc = ietf_netconf.Lock()
        lock_rpc.input.target.candidate = Empty()
        reply = self.es.execute_rpc(self.ncc, lock_rpc)
        self.assertIsNone(reply)

        unlock_rpc = ietf_netconf.Unlock()
        unlock_rpc.input.target.running = Empty()
        try:
            reply = self.es.execute_rpc(self.ncc, unlock_rpc)
        except Exception as e:
            self.assertIsInstance(e, YError)
Esempio n. 23
0
    def build_config(self,
                     apply=True,
                     attributes=None,
                     unconfig=False,
                     **kwargs):
        attributes = AttributesHelper(self, attributes)
        configurations = CliConfigBuilder(unconfig=unconfig)
        ydk_obj = ned.Native.Interface.Gigabitethernet()
        keep = string.digits + '//'
        ydk_obj.name = ''.join(i for i in attributes.value('name')
                               if i in keep)

        shutdown = attributes.value('shutdown')
        if shutdown is not None:
            if unconfig:
                # Special case: unconfiguring always applies shutdown
                ydk_obj.shutdown = Empty()
            elif shutdown:
                ydk_obj.shutdown = Empty()
            else:
                ydk_obj.shutdown = DELETE()

        ipv4 = attributes.value('ipv4')
        if ipv4:
            if unconfig:
                ydk_obj.ip.address.primary.address = DELETE()
                ydk_obj.ip.address.primary.mask = DELETE()
            else:
                ydk_obj.ip.address.primary.address = str(ipv4.ip)
                ydk_obj.ip.address.primary.mask = str(ipv4.netmask)

        vrf = attributes.value('vrf')
        if vrf:
            if unconfig:
                ydk_obj.vrf.forwarding = DELETE()
            else:
                ydk_obj.vrf.forwarding = vrf.name

        # instantiate crud service
        crud_service = CRUDService()

        if apply:

            # create netconf connection
            ncp = NetconfServiceProvider(self.device)

            crud_service.create(ncp, ydk_obj)
        else:
            return YangConfig(device=self.device,
                              ydk_obj=ydk_obj,
                              ncp=NetconfServiceProvider,
                              crud_service=crud_service.create)
Esempio n. 24
0
def config_ldp(mpls_ldp, ldp_interfaces):
    mpls_ldp.enable = Empty()          #as per the xml the </enable> variable doesnot have anything
    interface_list = mpls_ldp.default_vrf.interfaces.interface
                               #as per pyang/xml, above one is a list containing interface objects (which has name and enable inside)
    
    #in the below code for every interface to be configured, 
    #we are creating an instance of the ldp interface object
    #assigning the end variables i.e. interface_name to the actual interface string and enable varible to Empty.
    for intf in ldp_interfaces:
    	interface_obj = mpls_ldp.default_vrf.interfaces.Interface()
    
    	interface_obj.interface_name = intf
    	interface_obj.enable = Empty()
    	interface_list.append(interface_obj)
Esempio n. 25
0
def config_mpls_ldp(mpls_ldp):
    """Add config data to mpls_ldp object."""
    # enable LDP
    mpls_ldp.enable = Empty()
    # enable LDP on GigabitEthernet0/0/0/0
    interface = mpls_ldp.default_vrf.interfaces.Interface()
    interface.interface_name = "GigabitEthernet0/0/0/0"
    interface.enable = Empty()
    mpls_ldp.default_vrf.interfaces.interface.append(interface)
    # enable LDP on GigabitEthernet0/0/0/1
    interface = mpls_ldp.default_vrf.interfaces.Interface()
    interface.interface_name = "GigabitEthernet0/0/0/1"
    interface.enable = Empty()
    mpls_ldp.default_vrf.interfaces.interface.append(interface)
Esempio n. 26
0
    def build_config(self,
                     apply=True,
                     attributes=None,
                     unconfig=False,
                     **kwargs):
        attributes = AttributesHelper(self, attributes)
        configurations = CliConfigBuilder(unconfig=unconfig)
        interface_configurations = xr_ifmgr_cfg.InterfaceConfigurations()
        interface_configuration = interface_configurations.InterfaceConfiguration(
        )
        interface_configuration.active = "act"
        interface_configuration.interface_name = attributes.value('name')
        if unconfig and attributes.iswildcard:
            interface_configuration = DELETE()
        else:
            shutdown = attributes.value('shutdown')
            if shutdown is not None:
                if unconfig:
                    # Special case: unconfiguring always applies shutdown
                    interface_configuration.shutdown = Empty()
                elif shutdown:
                    interface_configuration.shutdown = Empty()
                else:
                    interface_configuration.shutdown = DELETE()

            ipv4 = attributes.value('ipv4')
            primary = interface_configuration.ipv4_network.addresses.Primary()
            if ipv4:
                primary.address = str(ipv4.ip)
                primary.netmask = str(ipv4.netmask)

            vrf = attributes.value('vrf')
            if vrf:
                interface_configuration.vrf = vrf.name

        # instantiate crud service
        crud_service = CRUDService()
        if apply:

            # create netconf connection
            ncp = NetconfServiceProvider(self.device)

            return crud_service.create(ncp, interface_configuration)
        else:
            return YangConfig(device=self.device,
                              unconfig=unconfig,
                              ncp=NetconfServiceProvider,
                              interface_configuration=interface_configuration,
                              crud_service=crud_service.create)
Esempio n. 27
0
    def commit(self,
               provider,
               confirmed=False,
               confirm_timeout=None,
               persist=False,
               persist_id=None):
        """Execute a commit operation to commit the candidate configuration as the
           device's new current configuration.

        Args:
            provider (ydk.providers.ServiceProvider): A provider instance.
            confirmed (bool): Perform a confirmed commit operation.
            confirm_timeout (int): The timeout interval for a confirmed commit.
            persist (str): Make a confirmed commit persistent. A persistent
                confirmed commit is not aborted if the NETCONF session
                terminates. The only way to abort a persistent confirmed commit
                is to let the timer expire, or to use the <cancel-commit>
                operation. The value of this parameter is a token that must be
                given in the 'persist-id' parameter of <commit> or
                <cancel-commit> operations in order to confirm or cancel the
                persistent confirmed commit.
                The token should be a random string.
            persist_id (str): This parameter is given in order to commit a
                persistent confirmed commit. The value must be equal to the
                value given in the 'persist' parameter to the <commit>
                operation. If it does not match, the operation fails with an
                'invalid-value' error.

        Returns:
            An ok reply string if operation succeeds.

        Raises:
            YPYModelError: If validation error occurs.
            YPYServiceError: If other error has occurred.
                Possible errors could be:
                    - A server side error
                    - If there isn't enough information in the entity to
                      prepare the message (missing keys for example).
        """
        self.service_logger.info('Executing commit RPC')
        rpc = ietf_netconf.CommitRpc()
        rpc.input.confirm_timeout = confirm_timeout
        rpc.input.persist_id = persist_id
        if confirmed:
            rpc.input.confirmed = Empty()
        if persist:
            rpc.input.persist = Empty()

        return self.executor.execute_rpc(provider, rpc)
Esempio n. 28
0
def _get_rpc_datastore_object(datastore, rpc_datastore_type):
    if isinstance(datastore, str):
        rpc_datastore_type.url = datastore
        return rpc_datastore_type
    elif datastore == Datastore.candidate:
        rpc_datastore_type.candidate = Empty()
        return rpc_datastore_type
    elif datastore == Datastore.running:
        rpc_datastore_type.running = Empty()
        return rpc_datastore_type
    elif datastore == Datastore.startup:
        rpc_datastore_type.startup = Empty()
        return rpc_datastore_type
    else:
        raise YPYDataValidationError('Invalid datastore specified')
Esempio n. 29
0
def run_routing(codec_service, provider):
    # set up routing policy definition
    routing_policy = RoutingPolicy()

    pass_all_policy_defn = RoutingPolicy.PolicyDefinitions.PolicyDefinition()
    pass_all_policy_defn.name = 'PASS-ALL'

    stmt = RoutingPolicy.PolicyDefinitions.PolicyDefinition.Statements.Statement(
    )
    stmt.name = "community-set1"
    stmt.conditions.bgp_conditions.match_community_set = RoutingPolicy.PolicyDefinitions.PolicyDefinition.Statements.Statement.Conditions.BgpConditions.MatchCommunitySet(
    )
    stmt.conditions.bgp_conditions.match_community_set.community_set = "COMMUNITY-SET1"
    stmt.conditions.bgp_conditions.match_community_set.match_set_options = MatchSetOptionsTypeEnum.ALL
    stmt.actions.accept_route = Empty()
    pass_all_policy_defn.statements.statement.append(stmt)

    routing_policy.policy_definitions.policy_definition.append(
        pass_all_policy_defn)
    pass_all_policy_defn._parent = routing_policy.policy_definitions

    comm_set = RoutingPolicy.DefinedSets.BgpDefinedSets.CommunitySets.CommunitySet(
    )
    comm_set.community_set_name = 'testing'
    comm_set.community_member.append("oooo")
    comm_set.community_member.append("a")
    routing_policy.defined_sets.bgp_defined_sets.community_sets.community_set.append(
        comm_set)

    routing_payload = codec_service.encode(provider, routing_policy)
    print routing_payload
    routing_entity = codec_service.decode(provider, routing_payload)
    print 'Encoded payload:\n', routing_payload, \
            '\nRe-encode the decoded payload:\n', codec_service.encode(provider, routing_entity)
    assert routing_payload == codec_service.encode(provider, routing_entity)
Esempio n. 30
0
    def _to_real_type_helper(self, elem, member, entity):
        _type = member.ptype
        text = elem.text
        if text is None:
            return Empty()
        elif _type == 'int':
            if is_digit(text):
                return int(text)
            else:
                return text
        elif _type == 'str':
            return text
        elif _type == 'bool':
            if text == 'false':
                return False
            else:
                return True
        elif _type == 'Decimal64':
            return Decimal64(text)

        elif _type == 'bits':
            pass

        else:
            pass