model driven programmability advancement OSPF configuration using NETCONF 1

# NETCONFを使ってOSPFを行う

![Screenshot_2024-11-25_07-22-50.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3943132/01abace0-33ea-c607-c65a-120b40f3122b.png)

ルーターのL3IPは事前に設定済み
R3とR4はすでに設定済みでOSPFが稼働済み
PythonプログラムでCSR1とCSR2を設定する
ncclientライブラリを使う
デバイス名.xmlファイルを使う
プログラム実行時にCSR1とCSR2はすべてのルーターとOSPFを形成


ルーター設定
```cisco_ios:IOS-XE1
hostname IOS-XE1
ip domain-name abc.com
crypto key generate rsa module 1024
ip ssh version 2
username admin privilege 15 password cisco
netconf ssh
netconf-yang
line vty 0 4
login local
transport input all
int gi1
ip address 10.255.1.101 255.255.255.0
description Connect to MGMT
no shut
int gi2
ip address 12.0.0.1 255.255.255.0
description Connect to IOS-XE2
no shut
int gi3
ip address 13.0.0.1 255.255.255.0
description Connect to IOS3
no shut
int gi4
ip address 14.0.0.1 255.255.255.0
description Connect to IOS4
no shut
```

```cisco_ios:IOS-XE2
hostname IOS-XE2
ip domain-name abc.com
crypto key generate rsa module 1024
ip ssh version 2
username admin privilege 15 password cisco
netconf ssh
netconf-yang
line vty 0 4
login local
transport input all
int gi1
ip address 10.255.1.102 255.255.255.0
description Connect to MGMT
no shut
int gi2
ip address 12.0.0.2 255.255.255.0
description Connect to IOS-XE1
no shut
int gi3
ip address 24.0.0.2 255.255.255.0
description Connect to IOS4
no shut
int gi4
ip address 23.0.0.2 255.255.255.0
description Connect to IOS3
no shut
```

```cisco_ios:IOS3
hostname IOS3
int gi0/1
ip address 13.0.0.3 255.255.255.0
description connected to IOS-XE1
no shut
int gi0/2
ip address 23.0.0.3 255.255.255.0
description connected to IOS-XE2
no shut
router ospf 1
router-id 3.3.3.3
interface range gi0/1-2
ip ospf 1 area 0
ip ospf network point-to-point
```

```cisco_ios:IOS4
hostname IOS4
int gi0/1
ip address 14.0.0.4 255.255.255.0
description connected to IOS-XE1
no shut
int gi0/2
ip address 24.0.0.4 255.255.255.0
description connected to IOS-XE2
no shut
router ospf 1
router-id 4.4.4.4
interface range gi0/1-2
ip ospf 1 area 0
ip ospf network point-to-point
```

## 方針
XMLの設定ファイルをルーターに送信して設定するが、
1.そもそも設定のためのXML記法を覚えるのが面倒くさいので手動でルーターを設定し設定したルーターの設定XMLをPythonで取得する。
2.そこからOSPFの設定を抜き出して設定XMLを投げるファイルを作る。

```cisco_ios:IOS-XE1追加
router ospf 1
router-id 1.1.1.1

interface gi2
ip ospf 1 area 0
ip ospf network point-to-point
```

```python:netconf_dummy.py
from ncclient import manager
from xml.dom.minidom import parseString

netconf_conn = manager.connect(
    host = "10.255.1.101",
    port = "830",
    username = "admin",
    password = "cisco",
    hostkey_verify = False    
)
print("NETCONF Connected...\n")

running_config = netconf_conn.get_config(source = "running")
pretty_config = parseString(running_config.xml).toprettyxml()
print(pretty_config)

```

# 実行結果
ルーターを設定し保存せずPythonを実行する
```xml:result
<?xml version="1.0" ?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:579a1529-52ef-4c59-a6b1-fc2f03f58c03">
        <data>
                <native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
                        <version>16.9</version>
                        <boot-start-marker/>
                        <boot-end-marker/>
                        <service>
                                <timestamps>
                                        <debug>
                                                <datetime>
                                                        <msec/>
                                                </datetime>
                                        </debug>
                                        <log>
                                                <datetime>
                                                        <msec/>
                                                </datetime>
                                        </log>
                                </timestamps>
                        </service>
                        <platform>
                                <console xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-platform">
                                        <output>serial</output>
                                </console>
                        </platform>
                        <hostname>IOS-XE1</hostname>
                        <username>
                                <name>admin</name>
                                <privilege>15</privilege>
                                <password>
                                        <encryption>0</encryption>
                                        <password>cisco</password>
                                </password>
                        </username>
                        <ip>
                                <domain>
                                        <name>abc.com</name>
                                </domain>
                                <forward-protocol>
                                        <protocol>nd</protocol>
                                </forward-protocol>
                                <ssh>
                                        <version>2</version>
                                </ssh>
                                <http xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-http">
                                        <authentication>
                                                <local/>
                                        </authentication>
                                        <server>true</server>
                                        <secure-server>true</secure-server>
                                </http>
                        </ip>
                        <interface>
                                <GigabitEthernet>
                                        <name>1</name>
                                        <description>connect to MGMT</description>
                                        <ip>
                                                <address>
                                                        <primary>
                                                                <address>10.255.1.101</address>
                                                                <mask>255.255.255.0</mask>
                                                        </primary>
                                                </address>
                                        </ip>
                                        <mop>
                                                <enabled>false</enabled>
                                                <sysid>false</sysid>
                                        </mop>
                                        <negotiation xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ethernet">
                                                <auto>true</auto>
                                        </negotiation>
                                </GigabitEthernet>
                                <GigabitEthernet>
                                        <name>2</name>
                                        <description>connect to IOS-XE2</description>
                                        <ip>
                                                <address>
                                                        <primary>
                                                                <address>12.0.0.1</address>
                                                                <mask>255.255.255.0</mask>
                                                        </primary>
                                                </address>
                                                <ospf xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ospf">
                                                        <process-id>
                                                                <id>1</id>
                                                                <area>0</area>
                                                        </process-id>
                                                        <network>point-to-point</network>
                                                </ospf>
                                        </ip>
                                        <mop>
                                                <enabled>false</enabled>
                                                <sysid>false</sysid>
                                        </mop>
                                        <negotiation xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ethernet">
                                                <auto>true</auto>
                                        </negotiation>
                                </GigabitEthernet>
                                <GigabitEthernet>
                                        <name>3</name>
                                        <description>connect to IOS3</description>
                                        <ip>
                                                <address>
                                                        <primary>
                                                                <address>13.0.0.1</address>
                                                                <mask>255.255.255.0</mask>
                                                        </primary>
                                                </address>
                                        </ip>
                                        <mop>
                                                <enabled>false</enabled>
                                                <sysid>false</sysid>
                                        </mop>
                                        <negotiation xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ethernet">
                                                <auto>true</auto>
                                        </negotiation>
                                </GigabitEthernet>
                                <GigabitEthernet>
                                        <name>4</name>
                                        <description>connect to IOS4</description>
                                        <ip>
                                                <address>
                                                        <primary>
                                                                <address>14.0.0.1</address>
                                                                <mask>255.255.255.0</mask>
                                                        </primary>
                                                </address>
                                        </ip>
                                        <mop>
                                                <enabled>false</enabled>
                                                <sysid>false</sysid>
                                        </mop>
                                        <negotiation xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ethernet">
                                                <auto>true</auto>
                                        </negotiation>
                                </GigabitEthernet>
                        </interface>
                        <control-plane/>
                        <login>
                                <on-success>
                                        <log/>
                                </on-success>
                        </login>
                        <multilink>
                                <bundle-name xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ppp">authenticated</bundle-name>
                        </multilink>
                        <redundancy/>
                        <spanning-tree>
                                <extend xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-spanning-tree">
                                        <system-id/>
                                </extend>
                        </spanning-tree>
                        <subscriber>
                                <templating/>
                        </subscriber>
                        <crypto>
                                <pki xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-crypto">
                                        <trustpoint>
                                                <id>TP-self-signed-3543432073</id>
                                                <enrollment>
                                                        <selfsigned/>
                                                </enrollment>
                                                <revocation-check>none</revocation-check>
                                                <rsakeypair>
                                                        <key-label>TP-self-signed-3543432073</key-label>
                                                </rsakeypair>
                                                <subject-name>cn=IOS-Self-Signed-Certificate-3543432073</subject-name>
                                        </trustpoint>
                                        <certificate>
                                                <chain>
                                                        <name>TP-self-signed-3543432073</name>
                                                        <certificate>
                                                                <serial>01</serial>
                                                                <certtype>self-signed</certtype>
                                                        </certificate>
                                                </chain>
                                        </certificate>
                                </pki>
                        </crypto>
                        <router>
                                <ospf xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ospf">
                                        <id>1</id>
                                        <router-id>1.1.1.1</router-id>
                                </ospf>
                        </router>
                        <license>
                                <udi>
                                        <pid>CSR1000V</pid>
                                        <sn>9DIAI7TO3OF</sn>
                                </udi>
                        </license>
                        <line>
                                <console>
                                        <first>0</first>
                                        <stopbits>1</stopbits>
                                </console>
                                <vty>
                                        <first>0</first>
                                        <last>4</last>
                                        <login>
                                                <local/>
                                        </login>
                                        <transport>
                                                <input>
                                                        <input>all</input>
                                                </input>
                                        </transport>
                                </vty>
                        </line>
                        <diagnostic xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-diagnostics">
                                <bootup>
                                        <level>minimal</level>
                                </bootup>
                        </diagnostic>
                </native>
                <licensing xmlns="http://cisco.com/ns/yang/cisco-smart-license">
                        <config>
                                <enable>false</enable>
                                <privacy>
                                        <hostname>false</hostname>
                                        <version>false</version>
                                </privacy>
                                <utility>
                                        <utility-enable>false</utility-enable>
                                </utility>
                        </config>
                </licensing>
                <interfaces xmlns="http://openconfig.net/yang/interfaces">
                        <interface>
                                <name>GigabitEthernet1</name>
                                <config>
                                        <name>GigabitEthernet1</name>
                                        <type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
                                        <description>connect to MGMT</description>
                                        <enabled>true</enabled>
                                </config>
                                <subinterfaces>
                                        <subinterface>
                                                <index>0</index>
                                                <config>
                                                        <index>0</index>
                                                        <description>connect to MGMT</description>
                                                        <enabled>true</enabled>
                                                </config>
                                                <ipv4 xmlns="http://openconfig.net/yang/interfaces/ip">
                                                        <addresses>
                                                                <address>
                                                                        <ip>10.255.1.101</ip>
                                                                        <config>
                                                                                <ip>10.255.1.101</ip>
                                                                                <prefix-length>24</prefix-length>
                                                                        </config>
                                                                </address>
                                                        </addresses>
                                                </ipv4>
                                                <ipv6 xmlns="http://openconfig.net/yang/interfaces/ip">
                                                        <config>
                                                                <enabled>false</enabled>
                                                        </config>
                                                </ipv6>
                                        </subinterface>
                                </subinterfaces>
                                <ethernet xmlns="http://openconfig.net/yang/interfaces/ethernet">
                                        <config>
                                                <mac-address>50:00:00:01:00:00</mac-address>
                                                <auto-negotiate>true</auto-negotiate>
                                        </config>
                                </ethernet>
                        </interface>
                        <interface>
                                <name>GigabitEthernet2</name>
                                <config>
                                        <name>GigabitEthernet2</name>
                                        <type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
                                        <description>connect to IOS-XE2</description>
                                        <enabled>true</enabled>
                                </config>
                                <subinterfaces>
                                        <subinterface>
                                                <index>0</index>
                                                <config>
                                                        <index>0</index>
                                                        <description>connect to IOS-XE2</description>
                                                        <enabled>true</enabled>
                                                </config>
                                                <ipv4 xmlns="http://openconfig.net/yang/interfaces/ip">
                                                        <addresses>
                                                                <address>
                                                                        <ip>12.0.0.1</ip>
                                                                        <config>
                                                                                <ip>12.0.0.1</ip>
                                                                                <prefix-length>24</prefix-length>
                                                                        </config>
                                                                </address>
                                                        </addresses>
                                                </ipv4>
                                                <ipv6 xmlns="http://openconfig.net/yang/interfaces/ip">
                                                        <config>
                                                                <enabled>false</enabled>
                                                        </config>
                                                </ipv6>
                                        </subinterface>
                                </subinterfaces>
                                <ethernet xmlns="http://openconfig.net/yang/interfaces/ethernet">
                                        <config>
                                                <mac-address>50:00:00:01:00:01</mac-address>
                                                <auto-negotiate>true</auto-negotiate>
                                        </config>
                                </ethernet>
                        </interface>
                        <interface>
                                <name>GigabitEthernet3</name>
                                <config>
                                        <name>GigabitEthernet3</name>
                                        <type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
                                        <description>connect to IOS3</description>
                                        <enabled>true</enabled>
                                </config>
                                <subinterfaces>
                                        <subinterface>
                                                <index>0</index>
                                                <config>
                                                        <index>0</index>
                                                        <description>connect to IOS3</description>
                                                        <enabled>true</enabled>
                                                </config>
                                                <ipv4 xmlns="http://openconfig.net/yang/interfaces/ip">
                                                        <addresses>
                                                                <address>
                                                                        <ip>13.0.0.1</ip>
                                                                        <config>
                                                                                <ip>13.0.0.1</ip>
                                                                                <prefix-length>24</prefix-length>
                                                                        </config>
                                                                </address>
                                                        </addresses>
                                                </ipv4>
                                                <ipv6 xmlns="http://openconfig.net/yang/interfaces/ip">
                                                        <config>
                                                                <enabled>false</enabled>
                                                        </config>
                                                </ipv6>
                                        </subinterface>
                                </subinterfaces>
                                <ethernet xmlns="http://openconfig.net/yang/interfaces/ethernet">
                                        <config>
                                                <mac-address>50:00:00:01:00:02</mac-address>
                                                <auto-negotiate>true</auto-negotiate>
                                        </config>
                                </ethernet>
                        </interface>
                        <interface>
                                <name>GigabitEthernet4</name>
                                <config>
                                        <name>GigabitEthernet4</name>
                                        <type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
                                        <description>connect to IOS4</description>
                                        <enabled>true</enabled>
                                </config>
                                <subinterfaces>
                                        <subinterface>
                                                <index>0</index>
                                                <config>
                                                        <index>0</index>
                                                        <description>connect to IOS4</description>
                                                        <enabled>true</enabled>
                                                </config>
                                                <ipv4 xmlns="http://openconfig.net/yang/interfaces/ip">
                                                        <addresses>
                                                                <address>
                                                                        <ip>14.0.0.1</ip>
                                                                        <config>
                                                                                <ip>14.0.0.1</ip>
                                                                                <prefix-length>24</prefix-length>
                                                                        </config>
                                                                </address>
                                                        </addresses>
                                                </ipv4>
                                                <ipv6 xmlns="http://openconfig.net/yang/interfaces/ip">
                                                        <config>
                                                                <enabled>false</enabled>
                                                        </config>
                                                </ipv6>
                                        </subinterface>
                                </subinterfaces>
                                <ethernet xmlns="http://openconfig.net/yang/interfaces/ethernet">
                                        <config>
                                                <mac-address>50:00:00:01:00:03</mac-address>
                                                <auto-negotiate>true</auto-negotiate>
                                        </config>
                                </ethernet>
                        </interface>
                </interfaces>
                <network-instances xmlns="http://openconfig.net/yang/network-instance">
                        <network-instance>
                                <name>default</name>
                                <config>
                                        <name>default</name>
                                        <type xmlns:oc-ni-types="http://openconfig.net/yang/network-instance-types">oc-ni-types:DEFAULT_INSTANCE</type>
                                        <description>default-vrf [read-only]</description>
                                </config>
                                <tables>
                                        <table>
                                                <protocol xmlns:oc-pol-types="http://openconfig.net/yang/policy-types">oc-pol-types:DIRECTLY_CONNECTED</protocol>
                                                <address-family xmlns:oc-types="http://openconfig.net/yang/openconfig-types">oc-types:IPV4</address-family>
                                                <config>
                                                        <protocol xmlns:oc-pol-types="http://openconfig.net/yang/policy-types">oc-pol-types:DIRECTLY_CONNECTED</protocol>
                                                        <address-family xmlns:oc-types="http://openconfig.net/yang/openconfig-types">oc-types:IPV4</address-family>
                                                </config>
                                        </table>
                                        <table>
                                                <protocol xmlns:oc-pol-types="http://openconfig.net/yang/policy-types">oc-pol-types:DIRECTLY_CONNECTED</protocol>
                                                <address-family xmlns:oc-types="http://openconfig.net/yang/openconfig-types">oc-types:IPV6</address-family>
                                                <config>
                                                        <protocol xmlns:oc-pol-types="http://openconfig.net/yang/policy-types">oc-pol-types:DIRECTLY_CONNECTED</protocol>
                                                        <address-family xmlns:oc-types="http://openconfig.net/yang/openconfig-types">oc-types:IPV6</address-family>
                                                </config>
                                        </table>
                                        <table>
                                                <protocol xmlns:oc-pol-types="http://openconfig.net/yang/policy-types">oc-pol-types:OSPF</protocol>
                                                <address-family xmlns:oc-types="http://openconfig.net/yang/openconfig-types">oc-types:IPV4</address-family>
                                                <config>
                                                        <protocol xmlns:oc-pol-types="http://openconfig.net/yang/policy-types">oc-pol-types:OSPF</protocol>
                                                        <address-family xmlns:oc-types="http://openconfig.net/yang/openconfig-types">oc-types:IPV4</address-family>
                                                </config>
                                        </table>
                                        <table>
                                                <protocol xmlns:oc-pol-types="http://openconfig.net/yang/policy-types">oc-pol-types:STATIC</protocol>
                                                <address-family xmlns:oc-types="http://openconfig.net/yang/openconfig-types">oc-types:IPV4</address-family>
                                                <config>
                                                        <protocol xmlns:oc-pol-types="http://openconfig.net/yang/policy-types">oc-pol-types:STATIC</protocol>
                                                        <address-family xmlns:oc-types="http://openconfig.net/yang/openconfig-types">oc-types:IPV4</address-family>
                                                </config>
                                        </table>
                                        <table>
                                                <protocol xmlns:oc-pol-types="http://openconfig.net/yang/policy-types">oc-pol-types:STATIC</protocol>
                                                <address-family xmlns:oc-types="http://openconfig.net/yang/openconfig-types">oc-types:IPV6</address-family>
                                                <config>
                                                        <protocol xmlns:oc-pol-types="http://openconfig.net/yang/policy-types">oc-pol-types:STATIC</protocol>
                                                        <address-family xmlns:oc-types="http://openconfig.net/yang/openconfig-types">oc-types:IPV6</address-family>
                                                </config>
                                        </table>
                                </tables>
                                <protocols>
                                        <protocol>
                                                <identifier xmlns:oc-pol-types="http://openconfig.net/yang/policy-types">oc-pol-types:OSPF</identifier>
                                                <name>1</name>
                                                <config>
                                                        <identifier xmlns:oc-pol-types="http://openconfig.net/yang/policy-types">oc-pol-types:OSPF</identifier>
                                                        <name>1</name>
                                                </config>
                                        </protocol>
                                        <protocol>
                                                <identifier xmlns:oc-pol-types="http://openconfig.net/yang/policy-types">oc-pol-types:STATIC</identifier>
                                                <name>DEFAULT</name>
                                                <config>
                                                        <identifier xmlns:oc-pol-types="http://openconfig.net/yang/policy-types">oc-pol-types:STATIC</identifier>
                                                        <name>DEFAULT</name>
                                                </config>
                                        </protocol>
                                        <protocol>
                                                <identifier xmlns:oc-pol-types="http://openconfig.net/yang/policy-types">oc-pol-types:DIRECTLY_CONNECTED</identifier>
                                                <name>DEFAULT</name>
                                                <config>
                                                        <identifier xmlns:oc-pol-types="http://openconfig.net/yang/policy-types">oc-pol-types:DIRECTLY_CONNECTED</identifier>
                                                        <name>DEFAULT</name>
                                                </config>
                                        </protocol>
                                </protocols>
                        </network-instance>
                </network-instances>
                <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
                        <interface>
                                <name>GigabitEthernet1</name>
                                <description>connect to MGMT</description>
                                <type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
                                <enabled>true</enabled>
                                <ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
                                        <address>
                                                <ip>10.255.1.101</ip>
                                                <netmask>255.255.255.0</netmask>
                                        </address>
                                </ipv4>
                                <ipv6 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip"/>
                        </interface>
                        <interface>
                                <name>GigabitEthernet2</name>
                                <description>connect to IOS-XE2</description>
                                <type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
                                <enabled>true</enabled>
                                <ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
                                        <address>
                                                <ip>12.0.0.1</ip>
                                                <netmask>255.255.255.0</netmask>
                                        </address>
                                </ipv4>
                                <ipv6 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip"/>
                        </interface>
                        <interface>
                                <name>GigabitEthernet3</name>
                                <description>connect to IOS3</description>
                                <type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
                                <enabled>true</enabled>
                                <ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
                                        <address>
                                                <ip>13.0.0.1</ip>
                                                <netmask>255.255.255.0</netmask>
                                        </address>
                                </ipv4>
                                <ipv6 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip"/>
                        </interface>
                        <interface>
                                <name>GigabitEthernet4</name>
                                <description>connect to IOS4</description>
                                <type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
                                <enabled>true</enabled>
                                <ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
                                        <address>
                                                <ip>14.0.0.1</ip>
                                                <netmask>255.255.255.0</netmask>
                                        </address>
                                </ipv4>
                                <ipv6 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip"/>
                        </interface>
                </interfaces>
                <nacm xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-acm">
                        <enable-nacm>true</enable-nacm>
                        <read-default>deny</read-default>
                        <write-default>deny</write-default>
                        <exec-default>deny</exec-default>
                        <enable-external-groups>true</enable-external-groups>
                        <rule-list>
                                <name>admin</name>
                                <group>PRIV15</group>
                                <rule>
                                        <name>permit-all</name>
                                        <module-name>*</module-name>
                                        <access-operations>*</access-operations>
                                        <action>permit</action>
                                </rule>
                        </rule-list>
                </nacm>
                <routing xmlns="urn:ietf:params:xml:ns:yang:ietf-routing">
                        <routing-instance>
                                <name>default</name>
                                <description>default-vrf [read-only]</description>
                                <routing-protocols>
                                        <routing-protocol>
                                                <type xmlns:ospf="urn:ietf:params:xml:ns:yang:ietf-ospf">ospf:ospfv2</type>
                                                <name>1</name>
                                                <ospf xmlns="urn:ietf:params:xml:ns:yang:ietf-ospf">
                                                        <instance>
                                                                <af xmlns:rt="urn:ietf:params:xml:ns:yang:ietf-routing">rt:ipv4</af>
                                                                <router-id>1.1.1.1</router-id>
                                                                <nsr>
                                                                        <enable>false</enable>
                                                                </nsr>
                                                                <auto-cost>
                                                                        <enable>false</enable>
                                                                </auto-cost>
                                                                <redistribution xmlns="urn:ietf:params:xml:ns:yang:cisco-ospf">
                                                                        <rip/>
                                                                </redistribution>
                                                        </instance>
                                                </ospf>
                                        </routing-protocol>
                                        <routing-protocol>
                                                <type>static</type>
                                                <name>1</name>
                                        </routing-protocol>
                                </routing-protocols>
                        </routing-instance>
                </routing>
        </data>
</rpc-reply>
```

ここから設定に必要な部分を抜き出す。
必要なのは<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">と
<interface>のOSPF設定部分
<routing xmlns="urn:ietf:params:xml:ns:yang:ietf-routing">ルーティングのOSPFの設定部分
抜き出したXMLを修正してXMLファイルを作る。
みてもらえばわかるが記法が独自で１から作るのは難しい。

```xml:ios-xe1.xml
<config>
    <native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
        <interface>
            <GigabitEthernet>
                    <name>2</name>
                    <description>connect to IOS-XE2</description>
                    <ip>
                            <address>
                                    <primary>
                                            <address>12.0.0.1</address>
                                            <mask>255.255.255.0</mask>
                                    </primary>
                            </address>
                            <ospf xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ospf">
                                    <process-id>
                                            <id>1</id>
                                            <area>0</area>
                                    </process-id>
                                    <network>point-to-point</network>
                            </ospf>
                    </ip>
                    <mop>
                            <enabled>false</enabled>
                            <sysid>false</sysid>
                    </mop>
                    <negotiation xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ethernet">
                            <auto>true</auto>
                    </negotiation>
            </GigabitEthernet>
            <GigabitEthernet>
                    <name>3</name>
                    <description>connect to IOS-XE3</description>
                    <ip>
                            <address>
                                    <primary>
                                            <address>13.0.0.1</address>
                                            <mask>255.255.255.0</mask>
                                    </primary>
                            </address>
                            <ospf xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ospf">
                                    <process-id>
                                            <id>1</id>
                                            <area>0</area>
                                    </process-id>
                                    <network>point-to-point</network>
                            </ospf>
                    </ip>
                    <mop>
                            <enabled>false</enabled>
                            <sysid>false</sysid>
                    </mop>
                    <negotiation xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ethernet">
                            <auto>true</auto>
                    </negotiation>
            </GigabitEthernet>
            <GigabitEthernet>
                    <name>4</name>
                    <description>connect to IOS-XE4</description>
                    <ip>
                            <address>
                                    <primary>
                                            <address>14.0.0.1</address>
                                            <mask>255.255.255.0</mask>
                                    </primary>
                            </address>
                            <ospf xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ospf">
                                    <process-id>
                                            <id>1</id>
                                            <area>0</area>
                                    </process-id>
                                    <network>point-to-point</network>
                            </ospf>
                    </ip>
                    <mop>
                            <enabled>false</enabled>
                            <sysid>false</sysid>
                    </mop>
                    <negotiation xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ethernet">
                            <auto>true</auto>
                    </negotiation>
            </GigabitEthernet>
        </interface>
        <router>
                <ospf xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ospf">
                        <id>1</id>
                        <router-id>1.1.1.1</router-id>
                </ospf>
        </router>
    </native>
</config>
```


```xml:ios-xe2.xml
<config>
    <native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
        <interface>
            <GigabitEthernet>
                    <name>2</name>
                    <description>connect to IOS-XE1</description>
                    <ip>
                            <address>
                                    <primary>
                                            <address>12.0.0.2</address>
                                            <mask>255.255.255.0</mask>
                                    </primary>
                            </address>
                            <ospf xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ospf">
                                    <process-id>
                                            <id>1</id>
                                            <area>0</area>
                                    </process-id>
                                    <network>point-to-point</network>
                            </ospf>
                    </ip>
                    <mop>
                            <enabled>false</enabled>
                            <sysid>false</sysid>
                    </mop>
                    <negotiation xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ethernet">
                            <auto>true</auto>
                    </negotiation>
            </GigabitEthernet>
            <GigabitEthernet>
                    <name>3</name>
                    <description>connect to IOS-XE4</description>
                    <ip>
                            <address>
                                    <primary>
                                            <address>24.0.0.2</address>
                                            <mask>255.255.255.0</mask>
                                    </primary>
                            </address>
                            <ospf xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ospf">
                                    <process-id>
                                            <id>1</id>
                                            <area>0</area>
                                    </process-id>
                                    <network>point-to-point</network>
                            </ospf>
                    </ip>
                    <mop>
                            <enabled>false</enabled>
                            <sysid>false</sysid>
                    </mop>
                    <negotiation xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ethernet">
                            <auto>true</auto>
                    </negotiation>
            </GigabitEthernet>
            <GigabitEthernet>
                    <name>4</name>
                    <description>connect to IOS-XE3</description>
                    <ip>
                            <address>
                                    <primary>
                                            <address>23.0.0.2</address>
                                            <mask>255.255.255.0</mask>
                                    </primary>
                            </address>
                            <ospf xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ospf">
                                    <process-id>
                                            <id>1</id>
                                            <area>0</area>
                                    </process-id>
                                    <network>point-to-point</network>
                            </ospf>
                    </ip>
                    <mop>
                            <enabled>false</enabled>
                            <sysid>false</sysid>
                    </mop>
                    <negotiation xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ethernet">
                            <auto>true</auto>
                    </negotiation>
            </GigabitEthernet>
        </interface>
        <router>
                <ospf xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ospf">
                        <id>1</id>
                        <router-id>2.2.2.2</router-id>
                </ospf>
        </router>
    </native>
</config>

```