Skip to content

Commit

Permalink
Merge pull request #29 from network-analytics/feature/update-yang-module
Browse files Browse the repository at this point in the history
Feature/update yang module
  • Loading branch information
ahuangfeng authored Apr 20, 2023
2 parents de0c470 + f765f2b commit 59c676d
Show file tree
Hide file tree
Showing 36 changed files with 5,693 additions and 97 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,4 @@ cython_debug/
*.pcap
pids
.DS_Store
yangs
yangs/yang-push
130 changes: 115 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
# Scapy generator for UDP-notif

This repository implements a mock generator for UDP-notif messages as defined in [draft-ietf-netconf-udp-notif-08](https://datatracker.ietf.org/doc/html/draft-ietf-netconf-udp-notif-08). This mock generator supports IPv4.
This repository implements a mock generator for YANG-push notifications using UDP-notif transport as defined in [draft-ietf-netconf-udp-notif-09](https://datatracker.ietf.org/doc/draft-ietf-netconf-udp-notif/09/). This mock generator supports IPv4.


### Supported IETF RFCs/drafts

The mock YANG-push notifications uses the following IETF RFCs and drafts. The supported variant is Configured Subscriptions defined in [RFC8641](https://datatracker.ietf.org/doc/rfc8641/).

- [RFC5277](https://datatracker.ietf.org/doc/rfc5277): Netconf Event Notifications
- [RFC8639](https://datatracker.ietf.org/doc/rfc8639): Subscription to YANG Notifications
- [RFC8641](https://datatracker.ietf.org/doc/rfc8641/): Subscription to YANG Notifications for Datastore Updates (Configured Subscriptions only)
- [draft-ietf-netconf-udp-notif-09](https://datatracker.ietf.org/doc/draft-ietf-netconf-udp-notif/09/): UDP-based Transport for Configured Subscriptions
- [draft-ietf-netconf-distributed-notif-06](https://datatracker.ietf.org/doc/draft-ietf-netconf-distributed-notif/06/): Subscription to Distributed Notifications
- [draft-ahuang-netconf-notif-yang-01](https://datatracker.ietf.org/doc/draft-ahuang-netconf-notif-yang/01/): YANG model for NETCONF Event Notifications
- [draft-tgraf-netconf-notif-sequencing-00](https://datatracker.ietf.org/doc/draft-tgraf-netconf-notif-sequencing/00/): Support of Hostname and Sequencing in YANG Notifications
- [draft-tgraf-yang-push-observation-time-00](https://datatracker.ietf.org/doc/draft-tgraf-yang-push-observation-time/00/): Support of Network Observation Timestamping in YANG Notifications
- [draft-tgraf-netconf-yang-notifications-versioning-03](https://datatracker.ietf.org/doc/draft-tgraf-netconf-yang-notifications-versioning/03/): Support of Versioning in YANG Notifications Subscription


## Dependencies (Tested in Python 3.6.8)
Required libraries are specified in `src/requirements.txt`
Expand All @@ -22,46 +38,130 @@ $ sudo python3 src/main.py <src_ipv4> <dst_ipv4> <port_src> <port_dst>

### Optional arguments

- `--initial-domain x` or `-i x` : (Integer) initial observation domain id, x >= 0, Default: `0`
- `--initial-domain <domain>` or `-i <domain>` : (Integer) initial observation domain id, `<domain>` >= 0, Default: `0`

- `--additional-domains x` or `-a x` : (Integer) amount of additional observation domains, x >= 0, Default: `0`
- `--additional-domains <obs_nb>` or `-a <obs_nb>` : (Integer) amount of additional observation domains, `<obs_nb>` >= 0, Default: `0`

- `--message-amount x` or `-n x` : (Integer) amount of messages to send, x >= 1, Default: `1`
- `--message-amount <msgs>` or `-n <msgs>` : (Integer) amount of notification messages to send, `<msgs>` >= 1, Default: `1`

- `--encoding <encoding>` or `-e <encoding>`: (String) encoding of the UDP-notif payload. Options: [`json`, `xml`]. Default: `json`.

- `--mtu x` or `-m x` : (Integer) maximum transmission unit, 16 < x < 65535, Default: `1500`
- `--mtu <value>` or `-m <value>` : (Integer) maximum transmission unit, 16 < `<value>` < 65535, Default: `1500`

- `--waiting-time f` or `-w f` : (Float) waiting time (in seconds) between two messages, x > 0, Default: `0`
- `--waiting-time <time>` or `-w <time>` : (Float) waiting time (in seconds) between two messages, `<time>` > 0, Default: `0`

- `--probability-of-loss f` or `-p f` : (Float) segment loss probability, 0 <= x < 1, Default: `0`
- `--probability-of-loss <loss>` or `-p <loss>` : (Float) segment loss probability, 0 <= `<loss>` < 1, Default: `0`

- `--logging-level s` or `-l s` : (String) logging level, s = none or s = warning or s = info or s = debug, Default: `info`
- `--logging-level <level>` or `-l <level>` : (String) logging level, `<level>` = none or `<level>` = warning or `<level>` = info or `<level>` = debug, Default: `info`

- `--capture <path>` or `-c <path>` : (String) Save a wireshark capture of the forwarded packets in the `<path>`. Default: `None` (disabled).

- `--legacy` or `-leg` : Generate legacy headers as defined in [draft-ietf-netconf-udp-pub-channel-05](https://datatracker.ietf.org/doc/draft-ietf-netconf-udp-pub-channel/), /!\ No segmentation is possible. Default: Disabled
- `--legacy` or `-leg` : Generate legacy headers as defined in [draft-ietf-netconf-udp-pub-channel-05](https://datatracker.ietf.org/doc/draft-ietf-netconf-udp-pub-channel/), /!\ No segmentation is possible. Default: Disabled.

- `--update-yang` or `-upd`: Simulate a YANG module update to a backward compatible YANG module. Default: Disabled.

## Examples

One YANG-push message [RFC8641](https://www.rfc-editor.org/rfc/rfc8641) using UDP-notif as transport.
One YANG-push message [RFC8641](https://datatracker.ietf.org/doc/rfc8641) using UDP-notif as transport.
```shell
$ sudo python3 src/main.py 192.0.2.65 192.0.2.66 10001 10010
```

Continuous stream of YANG-push messages [RFC8641](https://www.rfc-editor.org/rfc/rfc8641) using UDP-notif as transport.
Continuous stream of YANG-push messages [RFC8641](https://datatracker.ietf.org/doc/rfc8641) using UDP-notif as transport.
```shell
$ sudo python3 src/main.py 192.0.2.66 192.0.2.66 10001 10010 -n 0
```

### Simulating a YANG subscription update

This generator can also simulate a YANG module update in YANG-push.

```shell
$ sudo python3 src/main.py 192.0.2.65 192.0.2.66 10001 10010 -upd
```

#### Used YANG modules

The YANG modules used in [yang/interfaces](./yangs/interfaces/).

The mock generator emulates a subscription to the Xpath `/if:interfaces` of [[email protected]](./yangs/interfaces/ietf-interfaces%402018-02-20.yang)

```yang
module: ietf-interfaces
+--rw interfaces
+--rw interface* [name]
+--rw name string
+--rw description? string
+--rw type identityref
+--rw enabled? boolean
+--rw link-up-down-trap-enable? enumeration {if-mib}?
+--ro admin-status enumeration {if-mib}?
+--ro oper-status enumeration
+--ro last-change? yang:date-and-time
+--ro if-index int32 {if-mib}?
+--ro phys-address? yang:phys-address
+--ro higher-layer-if* interface-ref
+--ro lower-layer-if* interface-ref
+--ro speed? yang:gauge64
+--ro statistics
+--ro discontinuity-time yang:date-and-time
+--ro in-octets? yang:counter64
+--ro in-unicast-pkts? yang:counter64
+--ro in-broadcast-pkts? yang:counter64
+--ro in-multicast-pkts? yang:counter64
+--ro in-discards? yang:counter32
+--ro in-errors? yang:counter32
+--ro in-unknown-protos? yang:counter32
+--ro out-octets? yang:counter64
+--ro out-unicast-pkts? yang:counter64
+--ro out-broadcast-pkts? yang:counter64
+--ro out-multicast-pkts? yang:counter64
+--ro out-discards? yang:counter32
+--ro out-errors? yang:counter32
```

After the update of the subscription, the generator emulates pushing a new versioned of the same YANG module with a new leaf `mtu`. This new YANG module is defined in [[email protected]](./yangs/interfaces/ietf-interfaces%402023-04-30.yang). Note that this new YANG module is defined for test purposes and is not part of any IETF standard RFC.

```yang
module: ietf-interfaces
+--rw interfaces
+--rw interface* [name]
+--rw name string
+--rw description? string
+--rw mtu uint32
+--rw type identityref
+--rw enabled? boolean
+--rw link-up-down-trap-enable? enumeration {if-mib}?
+--ro admin-status enumeration {if-mib}?
+--ro oper-status enumeration
+--ro last-change? yang:date-and-time
+--ro if-index int32 {if-mib}?
+--ro phys-address? yang:phys-address
+--ro higher-layer-if* interface-ref
+--ro lower-layer-if* interface-ref
+--ro speed? yang:gauge64
+--ro statistics
+--ro discontinuity-time yang:date-and-time
+--ro in-octets? yang:counter64
+--ro in-unicast-pkts? yang:counter64
+--ro in-broadcast-pkts? yang:counter64
+--ro in-multicast-pkts? yang:counter64
+--ro in-discards? yang:counter32
+--ro in-errors? yang:counter32
+--ro in-unknown-protos? yang:counter32
+--ro out-octets? yang:counter64
+--ro out-unicast-pkts? yang:counter64
+--ro out-broadcast-pkts? yang:counter64
+--ro out-multicast-pkts? yang:counter64
+--ro out-discards? yang:counter32
+--ro out-errors? yang:counter32
```

## NETCONF configuration XML examples

As defined in [RFC8641](https://www.rfc-editor.org/rfc/rfc8641), configured subscriptions are configured via Netconf RPC `<edit-config>`.
As defined in [RFC8641](https://datatracker.ietf.org/doc/rfc8641), configured subscriptions are configured via Netconf RPC `<edit-config>`.

Examples of configuration files can be found in [configurations](./src/resources/xml/subscription/).

## Docker container
See [Docker docs](docker)

## Launch multiple simulations
- `./launch_multiple.sh <number_messages>` : launches multiple instances of the generator simuling multiple source ips and ports
6 changes: 3 additions & 3 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from unyte_generator.unyte_argparser import Unyte_argparser
from unyte_generator.unyte_generator import UDP_notif_generator
from unyte_generator.unyte_generator_legacy_proto import UDP_notif_generator_legacy
from unyte_generator.unyte_generator_draft_08 import UDP_notif_generator_draft_08
from unyte_generator.unyte_generator_draft_09 import UDP_notif_generator_draft_09


if __name__ == "__main__":
Expand All @@ -14,7 +14,7 @@
# use old udp-notif headers: draft-ietf-netconf-udp-pub-channel-05
if args.legacy:
mock_generator = UDP_notif_generator_legacy(args=args)
else: # draft-ietf-netconf-udp-notif-08
mock_generator = UDP_notif_generator_draft_08(args=args)
else: # draft-ietf-netconf-udp-notif-09
mock_generator = UDP_notif_generator_draft_09(args=args)

mock_generator.send_udp_notif()
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{
"ietf-notification:notification": {
"eventTime": "2023-03-25T08:30:11.22Z",
"ietf-notification-sequencing:sysName": "example-router",
"ietf-notification-sequencing:sequenceNumber": 1,
"ietf-yang-push:push-change-update": {
"id": 2222,
"ietf-yang-push-netobs-timestamping:state-changed-observation-time": "2023-03-25T08:30:11.22Z",
"datastore-contents": {
"yang-patch": {
"patch-id": "patch_54",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
{
"ietf-notification:notification": {
"eventTime": "2023-03-25T08:30:11.22Z",
"ietf-notification-sequencing:sysName": "example-router",
"ietf-notification-sequencing:sequenceNumber": 1,
"ietf-yang-push:push-update": {
"id": 6666,
"ietf-yang-push-netobs-timestamping:observation-time": "2023-03-25T08:30:11.22Z",
"datastore-contents": {
"ietf-interfaces:interfaces": [
{
"interface": {
"name": "eth0",
"type": "iana-if-type:ethernetCsmacd",
"oper-status": "up"
}
}
Expand Down
23 changes: 23 additions & 0 deletions src/resources/json/notifications/push-update-2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"ietf-notification:notification": {
"eventTime": "2023-03-25T08:30:11.22Z",
"ietf-notification-sequencing:sysName": "example-router",
"ietf-notification-sequencing:sequenceNumber": 1,
"ietf-yang-push:push-update": {
"id": 6666,
"ietf-yang-push-netobs-timestamping:observation-time": "2023-03-25T08:30:11.22Z",
"datastore-contents": {
"ietf-interfaces:interfaces": [
{
"interface": {
"name": "eth0",
"type": "iana-if-type:ethernetCsmacd",
"oper-status": "up",
"mtu": 1500
}
}
]
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
{
"ietf-notification:notification": {
"eventTime": "2023-03-25T08:30:11.22Z",
"ietf-notification-sequencing:sysName": "example-router",
"ietf-notification-sequencing:sequenceNumber": 1,
"ietf-yang-push:push-update": {
"id": 2222,
"ietf-yang-push-netobs-timestamping:observation-time": "2023-03-25T08:30:11.22Z",
"datastore-contents": {
"ietf-subscribed-notifications:subscriptions": {
"subscription": [
{
"id": 2222,
"ietf-yang-push:datastore": "ietf-datastores:operational",
"ietf-yang-push:datastore-xpath-filter": "/ietf-subscribed-notifications:subscriptions",
"ietf-yang-push-revision:revision": "2019-09-09",
"ietf-distributed-notif:message-observation-domain-id": [1,2],
"transport": "ietf-udp-notif-transport:udp-notif",
"encoding": "encode-xml",
"receivers": {
Expand All @@ -28,6 +33,8 @@
"id": 6666,
"ietf-yang-push:datastore": "ietf-datastores:operational",
"ietf-yang-push:datastore-xpath-filter": "/ietf-interfaces:interfaces",
"ietf-yang-push-revision:revision": "2014-05-08",
"ietf-distributed-notif:message-observation-domain-id": [1,2],
"transport": "ietf-udp-notif-transport:udp-notif",
"encoding": "encode-json",
"receivers": {
Expand Down
7 changes: 6 additions & 1 deletion src/resources/json/notifications/subscription-modified.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
{
"ietf-notification:notification": {
"eventTime": "2023-03-25T08:30:11.22Z",
"ietf-notification-sequencing:sysName": "example-router",
"ietf-notification-sequencing:sequenceNumber": 1,
"ietf-subscribed-notification:subscription-modified": {
"id": 6666,
"ietf-yang-push:datastore": "ietf-datastores:operational",
"ietf-yang-push:datastore-xpath-filter": "/if:interfaces",
"ietf-yang-push-revision:revision": "2014-05-08",
"ietf-distributed-notif:message-observation-domain-id": [1,2],
"transport": "ietf-udp-notif-transport:udp-notif",
"encoding": "encode-json",
"ietf-yang-push:periodic": {
"ietf-yang-push:period": 100
}
}
}
}
}
5 changes: 5 additions & 0 deletions src/resources/json/notifications/subscription-started.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
{
"ietf-notification:notification": {
"eventTime": "2023-03-25T08:30:11.22Z",
"ietf-notification-sequencing:sysName": "example-router",
"ietf-notification-sequencing:sequenceNumber": 1,
"ietf-subscribed-notification:subscription-started": {
"id": 6666,
"ietf-yang-push:datastore": "ietf-datastores:operational",
"ietf-yang-push:datastore-xpath-filter": "/if:interfaces",
"ietf-yang-push-revision:revision": "2014-05-08",
"ietf-distributed-notif:message-observation-domain-id": [1,2],
"transport": "ietf-udp-notif-transport:udp-notif",
"encoding": "encode-json",
"ietf-yang-push:periodic": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
{
"ietf-notification:notification": {
"eventTime": "2023-03-25T08:30:11.22Z",
"ietf-notification-sequencing:sysName": "example-router",
"ietf-notification-sequencing:sequenceNumber": 1,
"ietf-subscribed-notification:subscription-started": {
"id": 6666,
"ietf-yang-push:datastore": "ietf-datastores:operational",
"ietf-yang-push:datastore-xpath-filter": "/if:interfaces",
"ietf-yang-push-revision:revision": "2014-05-08",
"ietf-distributed-notif:message-observation-domain-id": [1,2],
"transport": "ietf-udp-notif-transport:udp-notif",
"encoding": "encode-json",
"ietf-yang-push:periodic": {
Expand Down
2 changes: 2 additions & 0 deletions src/resources/json/notifications/subscription-terminated.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"ietf-notification:notification": {
"eventTime": "2023-03-25T08:30:11.22Z",
"ietf-notification-sequencing:sysName": "example-router",
"ietf-notification-sequencing:sequenceNumber": 1,
"ietf-subscribed-notification:subscription-terminated": {
"id": 6666,
"reason": "no-such-subscription"
Expand Down
Loading

0 comments on commit 59c676d

Please sign in to comment.