def config_bgp(bgp):
    """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_ = 65001
    four_byte_as.bgp_running = Empty()
    # global address family
    global_af = four_byte_as.default_vrf.global_.global_afs.GlobalAf()
    global_af.af_name = xr_ipv4_bgp_datatypes.BgpAddressFamily.ipv4_unicast
    global_af.enable = Empty()
    four_byte_as.default_vrf.global_.global_afs.global_af.append(global_af)
    instance_as.four_byte_as.append(four_byte_as)
    instance.instance_as.append(instance_as)
    bgp.instance.append(instance)

    # configure IBGP neighbor group
    neighbor_groups = four_byte_as.default_vrf.bgp_entity.neighbor_groups
    neighbor_group = neighbor_groups.NeighborGroup()
    neighbor_group.neighbor_group_name = "IBGP"
    neighbor_group.create = Empty()
    # remote AS
    neighbor_group.remote_as.as_xx = 0
    neighbor_group.remote_as.as_yy = 65001
    neighbor_group.update_source_interface = "Loopback0"
    neighbor_groups.neighbor_group.append(neighbor_group)
    # ipv4 unicast
    neighbor_group_af = neighbor_group.neighbor_group_afs.NeighborGroupAf()
    neighbor_group_af.af_name = xr_ipv4_bgp_datatypes.BgpAddressFamily.ipv4_unicast
    neighbor_group_af.activate = Empty()
    neighbor_group_afs = neighbor_group.neighbor_group_afs
    neighbor_group_afs.neighbor_group_af.append(neighbor_group_af)

    # configure IBGP neighbor
    neighbor = four_byte_as.default_vrf.bgp_entity.neighbors.Neighbor()
    neighbor.neighbor_address = "172.16.255.2"
    neighbor.neighbor_group_add_member = "IBGP"
    four_byte_as.default_vrf.bgp_entity.neighbors.neighbor.append(neighbor)
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.rdm_keyword = xr_ip_rsvp_cfg.RsvpRdm.not_specified
    interface.bandwidth.rdm.bc0_keyword = xr_ip_rsvp_cfg.RsvpBc0.not_specified
    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.rdm_keyword = xr_ip_rsvp_cfg.RsvpRdm.not_specified
    interface.bandwidth.rdm.bc0_keyword = xr_ip_rsvp_cfg.RsvpBc0.not_specified
    interface.bandwidth.rdm.bandwidth_mode = xr_ip_rsvp_cfg.RsvpBwCfg.percentage
    rsvp.interfaces.interface.append(interface)
    def test_string(self):
        runner = self._create_runner()
        runner.ytypes.built_in_t.name = Empty()
        self.crud.create(self.ncc, runner)

        # Read into Runner2
        runner1 = ysanity.Runner()
        runner1 = self.crud.read(self.ncc, runner1)

        # Compare runners
        result = is_equal(runner, runner1)
        self.assertEqual(result, True)
Esempio n. 4
0
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 = "destGroup1"
    ipv4_destination = destination_group.ipv4_destinations.Ipv4Destination()
    ipv4_destination.destination_port = 5432
    ipv4_destination.ipv4_address = "167.205.3.41"
    ipv4_destination.destination_port = int("5432")
    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)
    telemetry_model_driven.enable = Empty()

    # sensor group
    sensor_group = telemetry_model_driven.sensor_groups.SensorGroup()
    sensor_group.sensor_group_identifier = "sensorGroup1"
    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 = "sensorGroup2"
    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 = "subscription1"
    sensor_profile = subscription.sensor_profiles.SensorProfile()
    sensor_profile.sensorgroupid = "sensorGroup1"
    sensor_profile.sample_interval = 5000
    subscription.sensor_profiles.sensor_profile.append(sensor_profile)
    sensor_profile = subscription.sensor_profiles.SensorProfile()
    sensor_profile.sensorgroupid = "sensorGroup2"
    sensor_profile.sample_interval = 8000
    subscription.sensor_profiles.sensor_profile.append(sensor_profile)
    destination_profile = subscription.destination_profiles.DestinationProfile(
    )
    destination_profile.destination_id = "destGroup1"
    subscription.destination_profiles.destination_profile.append(
        destination_profile)
    telemetry_model_driven.subscriptions.subscription.append(subscription)
Esempio n. 5
0
    def test_empty(self):
        runner = Runner()
        runner.ytypes.built_in_t.emptee = Empty()
        self.crud.create(self.ncc, runner)

        # Read into Runner1
        runner1 = Runner()
        runner1 = self.crud.read(self.ncc, runner1)

        # Compare runners
        self.assertEqual(runner, runner1)
        self.assertEqual(runner.ytypes.built_in_t.emptee, runner1.ytypes.built_in_t.emptee)
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.rdm_keyword = xr_ip_rsvp_cfg.RsvpRdmEnum.NOT_SPECIFIED
    interface.bandwidth.rdm.bc0_keyword = xr_ip_rsvp_cfg.RsvpBc0Enum.NOT_SPECIFIED
    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.rdm_keyword = xr_ip_rsvp_cfg.RsvpRdmEnum.NOT_SPECIFIED
    interface.bandwidth.rdm.bc0_keyword = xr_ip_rsvp_cfg.RsvpBc0Enum.NOT_SPECIFIED
    interface.bandwidth.rdm.bandwidth_mode = xr_ip_rsvp_cfg.RsvpBwCfgEnum.PERCENTAGE
    rsvp.interfaces.interface.append(interface)
Esempio n. 7
0
        def build_config(self,
                         apply=True,
                         attributes=None,
                         unconfig=False,
                         **kwargs):
            assert not kwargs
            attributes = AttributesHelper(self, attributes)
            configurations = CliConfigBuilder(unconfig=unconfig)
            vrfs = xr_infra_rsi_cfg.Vrfs()
            if not unconfig:
                vrf = vrfs.Vrf()
                if attributes.value('name'):
                    vrf.vrf_name = attributes.value('name')
                vrf.create = Empty()

                vrfs.vrf.append(vrf)
                #crud_service = CRUDService()
                #ncp = NetconfServiceProvider(self.device)
                #x = crud_service.read(ncp, vrf)
                #abc = YangConfig(device=self.device, ydk_obj=x, ncp=ncp, crud_service=crud_service)
                #print(abc)
                # iosxr: vrf vrf1 / address-family ipv4 unicast (config-vrf-af)
                for key, sub, attributes2 in attributes.mapping_items(
                        'address_family_attr',
                        keys=self.address_families,
                        sort=True):
                    sub.build_config(apply=False,
                                     attributes=attributes2,
                                     unconfig=unconfig,
                                     vrf=vrf)

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

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

                crud_service.create(ncp, vrfs)

                if unconfig:
                    crud_service.delete(ncp, vrfs)
            else:
                if unconfig:
                    return YangConfig(device=self.device,
                                      ydk_obj=vrfs,
                                      ncp=NetconfServiceProvider,
                                      crud_service=crud_service.delete)
                else:
                    return YangConfig(device=self.device,
                                      ydk_obj=vrfs,
                                      ncp=NetconfServiceProvider,
                                      crud_service=crud_service.create)
def config_routing_policy(routing_policy):
    """Add config data to routing_policy object."""
    # configure routing policy
    policy_definition = routing_policy.policy_definitions.PolicyDefinition()
    policy_definition.name = "POLICY1"
    policy_definition.config.name = "POLICY1"
    statement = policy_definition.statements.Statement()
    statement.name = "accept route"
    statement.config.name = "accept route"
    statement.actions.config.accept_route = Empty()
    policy_definition.statements.statement.append(statement)
    routing_policy.policy_definitions.policy_definition.append(policy_definition)
def config_isis(isis):
    """Add config data to isis object."""
    # global configuration
    instance = isis.instances.Instance()
    instance.instance_name = "DEFAULT"
    instance.running = Empty()
    instance.is_type = xr_clns_isis_cfg.IsisConfigurableLevels.level2
    net = instance.nets.Net()
    net.net_name = "49.0000.1720.1625.5001.00"
    instance.nets.net.append(net)
    isis.instances.instance.append(instance)
    # global address family
    af = instance.afs.Af()
    af.af_name = xr_clns_isis_datatypes.IsisAddressFamily.ipv6
    af.saf_name = xr_clns_isis_datatypes.IsisSubAddressFamily.unicast
    af.af_data = af.AfData()
    metric_style = af.af_data.metric_styles.MetricStyle()
    metric_style.style = xr_clns_isis_cfg.IsisMetricStyle.new_metric_style
    metric_style.level = xr_clns_isis_datatypes.IsisInternalLevel.not_set

    # segment routing
    mpls = xr_clns_isis_cfg.IsisLabelPreference.ldp
    af.af_data.segment_routing.mpls = mpls
    af.af_data.metric_styles.metric_style.append(metric_style)
    instance.afs.af.append(af)

    # loopback interface
    interface = instance.interfaces.Interface()
    interface.interface_name = "Loopback0"
    interface.running = Empty()
    interface.state = xr_clns_isis_cfg.IsisInterfaceState.passive
    # interface address family
    interface_af = interface.interface_afs.InterfaceAf()
    interface_af.af_name = xr_clns_isis_datatypes.IsisAddressFamily.ipv6
    interface_af.saf_name = xr_clns_isis_datatypes.IsisSubAddressFamily.unicast
    interface_af.interface_af_data.running = Empty()
    # segment routing
    prefix_sid = interface_af.interface_af_data.PrefixSid()
    prefix_sid.type = xr_clns_isis_cfg.Isissid1.absolute
    prefix_sid.value = 16061
    prefix_sid.php = xr_clns_isis_cfg.IsisphpFlag.enable
    explicit_null = xr_clns_isis_cfg.IsisexplicitNullFlag.disable
    prefix_sid.explicit_null = explicit_null
    prefix_sid.nflag_clear = xr_clns_isis_cfg.NflagClear.disable
    interface_af.interface_af_data.prefix_sid = prefix_sid
    interface.interface_afs.interface_af.append(interface_af)
    instance.interfaces.interface.append(interface)

    # gi0/0/0/0 interface
    interface = instance.interfaces.Interface()
    interface.interface_name = "GigabitEthernet0/0/0/0"
    interface.running = Empty()
    interface.point_to_point = Empty()
    # interface address familiy
    interface_af = interface.interface_afs.InterfaceAf()
    interface_af.af_name = xr_clns_isis_datatypes.IsisAddressFamily.ipv6
    interface_af.saf_name = xr_clns_isis_datatypes.IsisSubAddressFamily.unicast
    interface_af.interface_af_data.running = Empty()
    interface.interface_afs.interface_af.append(interface_af)
    instance.interfaces.interface.append(interface)
Esempio n. 10
0
def config_ntp(ntp):
    """Add config data to ntp object."""
    peer_vrf = ntp.peer_vrfs.PeerVrf()
    peer_vrf.vrf_name = "default"
    peer_ipv6 = peer_vrf.peer_ipv6s.PeerIpv6()
    peer_ipv6.address_ipv6 = "2001:db8::a:1"
    peer_type_ipv6 = peer_ipv6.PeerTypeIpv6()
    peer_type_ipv6.peer_type = xr_ip_ntp_cfg.NtpPeerEnum.SERVER
    peer_type_ipv6.source_interface = "Loopback0"
    peer_ipv6.peer_type_ipv6.append(peer_type_ipv6)
    peer_vrf.peer_ipv6s.peer_ipv6.append(peer_ipv6)
    ntp.peer_vrfs.peer_vrf.append(peer_vrf)
    ntp.update_calendar = Empty()
Esempio n. 11
0
def config_vrfs(vrfs):
    """Add config data to vrfs object."""
    # vrf RED
    vrf = vrfs.Vrf()
    vrf.vrf_name = "RED"
    vrf.create = Empty()

    # ipv6 unicast address family
    af = vrf.afs.Af()
    af.af_name = xr_infra_rsi_cfg.VrfAddressFamily.ipv6
    af.saf_name = xr_infra_rsi_cfg.VrfSubAddressFamily.unicast
    af.topology_name = "default"
    af.create = Empty()

    # import route targets
    route_target = af.bgp.import_route_targets.route_targets.RouteTarget()
    route_target.type = xr_ipv4_bgp_cfg.BgpVrfRouteTarget.as_
    as_or_four_byte_as = route_target.AsOrFourByteAs()
    as_or_four_byte_as.as_xx = 0
    as_or_four_byte_as.as_ = 65172
    as_or_four_byte_as.as_index = 1
    as_or_four_byte_as.stitching_rt = 0
    route_target.as_or_four_byte_as.append(as_or_four_byte_as)
    af.bgp.import_route_targets.route_targets.route_target.append(route_target)

    # export route targets
    route_target = af.bgp.export_route_targets.route_targets.RouteTarget()
    route_target.type = xr_ipv4_bgp_cfg.BgpVrfRouteTarget.as_
    as_or_four_byte_as = route_target.AsOrFourByteAs()
    as_or_four_byte_as.as_xx = 0
    as_or_four_byte_as.as_ = 65172
    as_or_four_byte_as.as_index = 1
    as_or_four_byte_as.stitching_rt = 0
    route_target.as_or_four_byte_as.append(as_or_four_byte_as)
    af.bgp.export_route_targets.route_targets.route_target.append(route_target)

    # append address family and vrf
    vrf.afs.af.append(af)
    vrfs.vrf.append(vrf)
def config_ntp(ntp):
    """Add config data to ntp object."""
    peer_vrf = ntp.peer_vrfs.PeerVrf()
    peer_vrf.vrf_name = "default"
    peer_ipv4 = peer_vrf.peer_ipv4s.PeerIpv4()
    peer_ipv4.address_ipv4 = "10.0.0.1"
    peer_type_ipv4 = peer_ipv4.PeerTypeIpv4()
    peer_type_ipv4.peer_type = xr_ip_ntp_cfg.NtpPeer.server
    peer_type_ipv4.source_interface = "Loopback0"
    peer_ipv4.peer_type_ipv4.append(peer_type_ipv4)
    peer_vrf.peer_ipv4s.peer_ipv4.append(peer_ipv4)
    ntp.peer_vrfs.peer_vrf.append(peer_vrf)
    ntp.update_calendar = Empty()
def config_routing_policy(routing_policy):
    """Add config data to routing_policy object."""
    # configure policy definition
    policy_definition = routing_policy.policy_definitions.PolicyDefinition()
    policy_definition.name = "POLICY4"
    statement = policy_definition.statements.Statement()
    statement.name = "next-hop-self"
    set_next_hop = oc_bgp_policy.BgpNextHopType.SELF
    statement.actions.bgp_actions.set_next_hop = set_next_hop
    statement.actions.accept_route = Empty()
    policy_definition.statements.statement.append(statement)
    routing_policy.policy_definitions.policy_definition.append(
        policy_definition)
Esempio n. 14
0
 def test_execute_validate_rpc(self):
     import logging
     log = logging.getLogger('ydk')
     log.setLevel(logging.INFO)
     handler = logging.StreamHandler()
     formatter = logging.Formatter(
         ("%(asctime)s - %(name)s - %(levelname)s - %(message)s"))
     handler.setFormatter(formatter)
     log.addHandler(handler)
     validate_rpc = ValidateRpc()
     validate_rpc.input.source.candidate = Empty()
     op = self.executor.execute_rpc(self.ncc, validate_rpc)
     self.assertEqual(None, op)
Esempio n. 15
0
    def test_execute_get_config_rpc(self):
        get_config_rpc = ietf_netconf.GetConfigRpc()
        get_config_rpc.input.source.candidate = Empty()
        initial_candidate_data = self.executor.execute_rpc(
            self.ncc, get_config_rpc)

        runner = ysanity.Runner()
        runner.two.number = 2
        runner.two.name = 'runner:two:name'

        edit_rpc = ietf_netconf.EditConfigRpc()
        edit_rpc.input.target.candidate = Empty()
        edit_rpc.input.config = runner
        op = self.executor.execute_rpc(self.ncc, edit_rpc)
        self.assertIn('ok', op)

        final_candidate_data = self.executor.execute_rpc(
            self.ncc, get_config_rpc)

        self.assertNotEqual(initial_candidate_data, final_candidate_data)
        self.assertNotIn(runner.two.name, initial_candidate_data)
        self.assertIn(runner.two.name, final_candidate_data)
Esempio n. 16
0
        def build_config(self,
                         apply=True,
                         attributes=None,
                         unconfig=False,
                         **kwargs):

            attributes = AttributesHelper(self, attributes)
            configurations = CliConfigBuilder(unconfig=unconfig)
            ospf = xr_ipv4_ospf_cfg.Ospf()
            process = ospf.processes.Process()
            id = attributes.value('ospf_name', force=True)
            process.process_name = str(id)
            ospf.processes.process.append(process)
            if not unconfig:
                process.start = Empty()
                # crud_service = CRUDService()
                # ncp = NetconfServiceProvider(self.device)
                # x = crud_service.read(ncp, process)
                # abc = YangConfig(device=self.device, ydk_obj=x, ncp=ncp, crud_service=crud_service)
                # print(abc)
                v = attributes.value('nsr')
                if v == True:
                    process.nsr = "true"
                for sub, attributes2 in attributes.mapping_values(
                        'vrf_attr', sort=VrfSubAttributes._sort_key):
                    sub.build_config(apply=False,
                                     attributes=attributes2,
                                     unconfig=unconfig,
                                     process=process,
                                     **kwargs)
            # instantiate crud service
            crud_service = CRUDService()
            if apply:

                # create netconf connection3
                ncp = NetconfServiceProvider(self.device)
                if unconfig:
                    crud_service.delete(ncp, process)
                else:
                    crud_service.create(ncp, process)
            else:
                if unconfig:
                    return YangConfig(device=self.device,
                                      ydk_obj=process,
                                      ncp=NetconfServiceProvider,
                                      crud_service=crud_service.delete)
                else:
                    return YangConfig(device=self.device,
                                      ydk_obj=process,
                                      ncp=NetconfServiceProvider,
                                      crud_service=crud_service.create)
Esempio n. 17
0
def config_interface_configurations(interface_configurations):
    """Add config data to interface_configurations object."""
    # configure IPv6 loopback
    interface_configuration = interface_configurations.InterfaceConfiguration()
    interface_configuration.active = "act"
    interface_configuration.interface_name = "Loopback0"
    interface_configuration.interface_virtual = Empty()
    interface_configuration.description = "PRIMARY ROUTER LOOPBACK"
    addresses = interface_configuration.ipv6_network.addresses
    regular_address = addresses.regular_addresses.RegularAddress()
    regular_address.address = "2001:db8::ff:1"
    regular_address.prefix_length = 128
    addresses.regular_addresses.regular_address.append(regular_address)
    interface_configurations.interface_configuration.append(interface_configuration)
def config_interface_configurations(interface_configurations):
    """Add config data to interface_configurations object."""
    # configure IPv4 loopback
    interface_configuration = interface_configurations.InterfaceConfiguration()
    interface_configuration.active = "act"
    interface_configuration.interface_name = "Loopback0"
    interface_configuration.interface_virtual = Empty()
    interface_configuration.description = "PRIMARY ROUTER LOOPBACK"
    primary = interface_configuration.ipv4_network.addresses.Primary()
    primary.address = "172.16.255.1"
    primary.netmask = "255.255.255.255"
    interface_configuration.ipv4_network.addresses.primary = primary
    interface_configurations.interface_configuration.append(
        interface_configuration)
Esempio n. 19
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 = 1000000
    interface.bandwidth.rdm.bc1_bandwidth = 250000
    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
    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 = 1000000
    interface.bandwidth.rdm.bc1_bandwidth = 250000
    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
    rsvp.interfaces.interface.append(interface)
Esempio n. 20
0
 def build_config(self,
                  area_area_id,
                  apply=True,
                  attributes=None,
                  unconfig=False,
                  **kwargs):
     assert not apply
     attributes = AttributesHelper(self, attributes)
     configurations = CliConfigBuilder(unconfig=unconfig)
     intf_name = attributes.value('interface_name')
     name_scope = area_area_id.name_scopes.NameScope()
     name_scope.interface_name = intf_name
     name_scope.running = Empty()
     area_area_id.name_scopes.name_scope.append(name_scope)
Esempio n. 21
0
    def test_execute_get_config_rpc(self):
        get_config_rpc = GetConfigRpc()
        get_config_rpc.input.source.candidate = Empty()
        get_config_rpc.input.filter = Runner()
        initial_candidate_data = self.executor.execute_rpc(
            self.ncc, get_config_rpc)

        runner = Runner()
        runner.two.number = 2
        runner.two.name = 'runner:two:name'

        edit_rpc = EditConfigRpc()
        edit_rpc.input.target.candidate = Empty()
        edit_rpc.input.config = runner
        op = self.executor.execute_rpc(self.ncc, edit_rpc)
        self.assertEqual(None, op)

        final_candidate_data = self.executor.execute_rpc(
            self.ncc, get_config_rpc)

        # self.assertNotEqual(initial_candidate_data, final_candidate_data) #TODO
        self.assertNotEqual(None, initial_candidate_data)
        self.assertNotEqual(None, final_candidate_data)
Esempio n. 22
0
def config_ospf(ospf):
    """Add config data to ospf object."""
    # OSPF process
    process = ospf.processes.Process()
    process.process_name = "100"
    process.default_vrf.router_id = "50.1.1.1"
    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()

    # 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)

    # GigabitEthernet0/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.OspfNetwork.point_to_point
    area_area_id.name_scopes.name_scope.append(name_scope)

    # GigabitEthernet0/0/0/1 interface
    name_scope = area_area_id.name_scopes.NameScope()
    name_scope.interface_name = "GigabitEthernet0/0/0/1"
    name_scope.running = Empty()
    name_scope.network_type = xr_ipv4_ospf_cfg.OspfNetwork.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. 23
0
    def eigrp(x, y):
        x.id = netmodel.eigrpName
        addconfig = x.AddressFamily()
        addconfig.type = Cisco_IOS_XE_native.Native.Router.Eigrp.AddressFamily.TypeEnum.ipv4
        iplist = x.AddressFamily.AfIpList()
        iplist.unicast_multicast = Cisco_IOS_XE_native.Native.Router.Eigrp.AddressFamily.AfIpList.UnicastMulticastEnum.unicast
        iplist.autonomous_system = netmodel.eigrpAS
        # iplist.maximum_paths = 16
        iplist.eigrp.router_id = y.loopback0
        aflist = Cisco_IOS_XE_native.Native.Router.Eigrp.AddressFamily.AfIpList.AfInterface()
        aflist.name = 'default'
        # aflist.passive_interface = Empty()
        aflist.authentication.mode.hmac_sha_256.auth_type = 7
        aflist.authentication.mode.hmac_sha_256.auth_key = netmodel.eigrpSHA256key
        # CREATE IF STATEMENT TO MAKE PRESENCSE CLASS FOR STUB ROUTING
        if y.stub == True:
            iplist.eigrp.stub = Cisco_IOS_XE_native.Native.Router.Eigrp.Eigrp_.Stub()
            iplist.eigrp.stub.connected = Empty()
            iplist.nsf = None
        else:
            iplist.eigrp.stub = None
            iplist.nsf = Empty()

        iplist.topology.base = Cisco_IOS_XE_native.Native.Router.Eigrp.AddressFamily.AfIpList.Topology.Base()

        def netlistappender(appendto, network):
            obj = Cisco_IOS_XE_native.Native.Router.Eigrp.AddressFamily.AfIpList.Network()
            obj.number = network[0]
            obj.wild_card = network[1]
            appendto.append(obj)

        for eigrpnetlist in netmodel.eigrpNetworks.items():
            netlistappender(iplist.network, eigrpnetlist)

        iplist.af_interface.append(aflist)
        addconfig.af_ip_list.append(iplist)
        x.address_family.append(addconfig)
Esempio n. 24
0
def run_test(provider):
    root = provider.get_session().get_root_schema()
    service = gNMIService()
    """Create interface configuration"""
    ifc = ifmgr.InterfaceConfigurations.InterfaceConfiguration()
    ifc.active = 'act'
    ifc.interface_name = 'Loopback10'
    ifc.description = 'Test interface'
    ifc.interface_virtual = Empty()

    ip_address = ifmgr.InterfaceConfigurations.InterfaceConfiguration.Ipv4Network.Addresses.Primary(
    )
    ip_address.address = '172.16.255.1'
    ip_address.netmask = '255.255.255.255'
    ifc.ipv4_network.addresses.primary = ip_address

    ifc_create = ifmgr.InterfaceConfigurations()
    ifc_create.interface_configuration.append(ifc)
    ifc_create.yfilter = YFilter.update

    reply = service.set(provider, ifc_create)
    """Read interface configuration"""
    ifc_filter = ifmgr.InterfaceConfigurations()
    ifc = ifmgr.InterfaceConfigurations.InterfaceConfiguration()
    ifc.active = '"act"'
    ifc.interface_name = '"Loopback10"'
    ifc_filter.interface_configuration.append(ifc)

    ifc_read = service.get(provider, ifc_filter)
    if ifc_read is not None:
        print_entity(ifc_read, root)
        """Need to fix bug in the XR bundle: missing directory _yang in distribution:
           RuntimeError: YIllegalStateError: Could not create repository in: /usr/local/lib/python2.7/dist-packages/ydk/models/cisco_ios_xr/_yang
        from ydk.services import CodecService
        from ydk.providers import CodecServiceProvider
        codec_service = CodecService()
        codec_provider = CodecServiceProvider(type='json')
        payload = codec_service.encode(codec_provider, ifc_read)
        print('CREATED INTERFACE CONFIGURATION:')
        print(payload)
        """
    """Delete interface configuration"""
    ifc_delete = ifmgr.InterfaceConfigurations()
    ifc = ifmgr.InterfaceConfigurations.InterfaceConfiguration()
    ifc.active = '"act"'
    ifc.interface_name = '"Loopback10"'
    ifc_delete.interface_configuration.append(ifc)
    ifc_delete.yfilter = YFilter.delete
    reply = service.set(provider, ifc_delete)
Esempio n. 25
0
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.tcp
    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)

    # 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)
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-SET"
    prefix = prefix_set.Prefix()
    prefix.ip_prefix = "10.0.0.0/8"
    prefix.masklength_range = "8..32"
    prefix_set.prefix.append(prefix)
    prefix = prefix_set.Prefix()
    prefix.ip_prefix = "172.16.0.0/12"
    prefix.masklength_range = "12..32"
    prefix_set.prefix.append(prefix)
    routing_policy.defined_sets.prefix_sets.prefix_set.append(prefix_set)

    # configure policy definition
    policy_definition = routing_policy.policy_definitions.PolicyDefinition()
    policy_definition.name = "ROUTE-POLICY"
    # configure drop-prefix statement
    statement = policy_definition.statements.Statement()
    statement.name = "DROP-PREFIXES"
    match_prefix_set = statement.conditions.MatchPrefixSet()
    match_prefix_set.prefix_set = "PREFIX-SET"
    match_set_options = oc_policy_types.MatchSetOptionsRestrictedTypeEnum.ANY
    match_prefix_set.match_set_options = match_set_options
    statement.conditions.match_prefix_set = match_prefix_set
    statement.actions.reject_route = Empty()
    policy_definition.statements.statement.append(statement)
    # configure accept statement
    statement = policy_definition.statements.Statement()
    statement.name = "ACCEPT-ROUTE"
    statement.actions.accept_route = Empty()
    policy_definition.statements.statement.append(statement)

    routing_policy.policy_definitions.policy_definition.append(
        policy_definition)
    def test_execute_rpc_invalid_1(self):
        runner = ysanity.Runner()
        runner.one.number = 1
        runner.one.name = 'runner:one:name'

        edit_rpc = ietf_netconf.EditConfigRpc()
        edit_rpc.input.target.candidate = Empty()
        edit_rpc.input.config = runner
        try:
            op = self.executor.execute_rpc(None, edit_rpc)
        except YPYServiceError as err:
            expected_msg = "'provider' and 'rpc' cannot be None"
            self.assertEqual(err.message, expected_msg)
        else:
            raise Exception('YPYServiceError not raised')
Esempio n. 28
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 = "1.1.1.1"
    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()
    name_scope.network_type = xr_ipv4_ospf_cfg.OspfNetwork.point_to_point
    area_area_id.name_scopes.name_scope.append(name_scope)

    # Area 1
    area_area_id_1 = process.default_vrf.area_addresses.AreaAreaId()
    area_area_id_1.area_id = 1
    area_area_id_1.running = Empty()

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

    # append area/process config
    process.default_vrf.area_addresses.area_area_id.append(area_area_id)
    process.default_vrf.area_addresses.area_area_id.append(area_area_id_1)
    ospf.processes.process.append(process)
    def test_execute_rpc_invalid_1(self):
        runner = ysanity.Runner()
        runner.ydktest_sanity_one.number = 1
        runner.ydktest_sanity_one.name = 'runner:one:name'

        edit_rpc = ietf_netconf.EditConfig()
        edit_rpc.input.target.candidate = Empty()
        runner_xml = self.codec.encode(self.codec_provider, runner)
        edit_rpc.input.config = runner_xml
        try:
            op = self.executor.execute_rpc(None, edit_rpc)
        except YServiceError as err:
            expected_msg = "provider and entity cannot be None"
            self.assertEqual(err.message, expected_msg)
        else:
            raise Exception('YServiceError not raised')
def config_syslog(syslog):
    """Add config data to syslog_service object."""
    rule = syslog.suppression.rules.Rule()
    rule.name = "RULE1"
    alarm_cause = rule.alarm_causes.AlarmCause()
    alarm_cause.category = "MGBL"
    alarm_cause.group = "CONFIG"
    alarm_cause.code = "DB_COMMIT"
    rule.alarm_causes.alarm_cause.append(alarm_cause)
    alarm_cause = rule.alarm_causes.AlarmCause()
    alarm_cause.category = "SECURITY"
    alarm_cause.group = "LOGIN"
    alarm_cause.code = "AUTHEN_SUCCESS"
    rule.alarm_causes.alarm_cause.append(alarm_cause)
    rule.applied_to.all = Empty()
    syslog.suppression.rules.rule.append(rule)