This repository has been archived by the owner on Nov 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
cd_encode_58.go
146 lines (127 loc) · 5.31 KB
/
cd_encode_58.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
* ------------------------------------------------------------------
* YANG Development Kit
* Copyright 2017 Cisco Systems. All rights reserved
*
*----------------------------------------------
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http:www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*----------------------------------------------
*/
package main
import (
"flag"
"fmt"
isisCfg "github.com/CiscoDevNet/ydk-go/ydk/models/cisco_ios_xr/clns_isis_cfg"
isisDatatypes "github.com/CiscoDevNet/ydk-go/ydk/models/cisco_ios_xr/clns_isis_datatypes"
"github.com/CiscoDevNet/ydk-go/ydk/providers"
"github.com/CiscoDevNet/ydk-go/ydk/services"
"github.com/CiscoDevNet/ydk-go/ydk"
"github.com/CiscoDevNet/ydk-go/ydk/types"
encoding "github.com/CiscoDevNet/ydk-go/ydk/types/encoding_format"
)
// configIsis adds config data to isis object.
func configIsis(isis *isisCfg.Isis) {
// global configuration
isis.Instances = isisCfg.Isis_Instances{
Instance: make([]isisCfg.Isis_Instances_Instance, 1) }
instance := &isis.Instances.Instance[0]
instance.InstanceName = "DEFAULT"
instance.Running = types.Empty{}
instance.IsType = isisCfg.IsisConfigurableLevels_level2
instance.Nets = isisCfg.Isis_Instances_Instance_Nets{
Net: make([]isisCfg.Isis_Instances_Instance_Nets_Net, 1) }
net := &instance.Nets.Net[0]
net.NetName = "49.0000.1720.1625.5002.00"
// global address family
instance.Afs = isisCfg.Isis_Instances_Instance_Afs{
Af: make([]isisCfg.Isis_Instances_Instance_Afs_Af, 1) }
af := &instance.Afs.Af[0]
af.AfName = isisDatatypes.IsisAddressFamily_ipv4
af.SafName = isisDatatypes.IsisSubAddressFamily_unicast
af.AfData = isisCfg.Isis_Instances_Instance_Afs_Af_AfData{}
af.AfData.MetricStyles = isisCfg.Isis_Instances_Instance_Afs_Af_AfData_MetricStyles{
MetricStyle: make(
[]isisCfg.Isis_Instances_Instance_Afs_Af_AfData_MetricStyles_MetricStyle, 1) }
metricStyle := &af.AfData.MetricStyles.MetricStyle[0]
metricStyle.Style = isisCfg.IsisMetricStyle_new_metric_style
metricStyle.Level = isisDatatypes.IsisInternalLevel_not_set
transitionState := isisCfg.IsisMetricStyleTransition_disabled
metricStyle.TransitionState = transitionState
// segment routing
mpls := isisCfg.IsisLabelPreference_ldp
af.AfData.SegmentRouting.Mpls = mpls
af.AfData.SegmentRouting.PrefixSidMap.Receive = true
// loopback interface
instance.Interfaces = isisCfg.Isis_Instances_Instance_Interfaces{
Interface_: make([]isisCfg.Isis_Instances_Instance_Interfaces_Interface, 2) }
intrface := &instance.Interfaces.Interface_[0]
intrface.InterfaceName = "Loopback0"
intrface.Running = types.Empty{}
intrface.State = isisCfg.IsisInterfaceState_passive
// interface address family
intrface.InterfaceAfs = isisCfg.Isis_Instances_Instance_Interfaces_Interface_InterfaceAfs{
InterfaceAf: make(
[]isisCfg.Isis_Instances_Instance_Interfaces_Interface_InterfaceAfs_InterfaceAf, 1) }
interfaceAf := &intrface.InterfaceAfs.InterfaceAf[0]
interfaceAf.AfName = isisDatatypes.IsisAddressFamily_ipv4
interfaceAf.SafName = isisDatatypes.IsisSubAddressFamily_unicast
interfaceAf.InterfaceAfData.Running = types.Empty{}
// segment routing
prefixSID := &interfaceAf.InterfaceAfData.PrefixSid
prefixSID.Type_ = isisCfg.Isissid1_absolute
prefixSID.Value = 16042
prefixSID.Php = isisCfg.IsisphpFlag_enable
prefixSID.ExplicitNull = isisCfg.IsisexplicitNullFlag_disable
prefixSID.NflagClear = isisCfg.NflagClear_disable
// gi0/0/0/0 interface
intrface = &instance.Interfaces.Interface_[1]
intrface.InterfaceName = "GigabitEthernet0/0/0/0"
intrface.Running = types.Empty{}
intrface.PointToPoint = types.Empty{}
// interface address family
intrface.InterfaceAfs = isisCfg.Isis_Instances_Instance_Interfaces_Interface_InterfaceAfs{
InterfaceAf: make(
[]isisCfg.Isis_Instances_Instance_Interfaces_Interface_InterfaceAfs_InterfaceAf, 1) }
interfaceAf = &intrface.InterfaceAfs.InterfaceAf[0]
interfaceAf.AfName = isisDatatypes.IsisAddressFamily_ipv4
interfaceAf.SafName = isisDatatypes.IsisSubAddressFamily_unicast
interfaceAf.InterfaceAfData.Running = types.Empty{}
}
// main executes main program.
func main() {
defer func() {
if r := recover(); r != nil {
fmt.Println("\nError occured!!\n ", r)
}
}()
vPtr := flag.Bool("v", false, "Enable verbose")
flag.Parse()
if *vPtr {
ydk.EnableLogging(ydk.Info)
}
// create codec provider
var provider = providers.CodecServiceProvider{}
provider.Encoding = encoding.XML
// create codec service
var service = services.CodecService{}
isis := isisCfg.Isis{} // create an object
configIsis(&isis) // add object configuration
// encode and print object
payload := service.Encode(&provider, &isis)
fmt.Println(payload)
}