From f500da8e2a198a636a0f5771267da0b116f182b6 Mon Sep 17 00:00:00 2001 From: Anton Ivanov Date: Fri, 30 Nov 2018 09:23:21 +0000 Subject: [PATCH 1/3] Add model for dhcp agent Signed-off-by: Anton Ivanov --- Makefile.am | 15 +- yang-models/dhcp-agent.yang | 360 ++++++++++++++++++++++++++++++++++++ 2 files changed, 371 insertions(+), 4 deletions(-) create mode 100644 yang-models/dhcp-agent.yang diff --git a/Makefile.am b/Makefile.am index b3316f4..f1eeca3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -64,7 +64,8 @@ YANG_PARSED_FILES = \ $(top_srcdir)/yang-models/system-status.yang \ $(top_srcdir)/yang-models/ipsec-sad.yang \ $(top_srcdir)/yang-models/tunnel.yang \ - $(top_srcdir)/yang-models/app-ztd.yang + $(top_srcdir)/yang-models/app-ztd.yang \ + $(top_srcdir)/yang-models/dhcp-agent.yang #Create VPATH for yang models @@ -136,7 +137,8 @@ YANG_GENERATED_SRCS = \ @YANG_OUTPUT@/system-status.cpp \ @YANG_OUTPUT@/yang-models/ipsec-sad.cpp \ @YANG_OUTPUT@/yang-models/tunnel.cpp \ - @YANG_OUTPUT@/yang-models/app-ztd.cpp + @YANG_OUTPUT@/yang-models/app-ztd.cpp \ + @YANG_OUTPUT@/yang-models/dhcp-agent.cpp YANG_GENERATED_HDRS = \ @YANG_OUTPUT@/yumaworks-extensions.h \ @@ -203,7 +205,8 @@ YANG_GENERATED_HDRS = \ @YANG_OUTPUT@/system-status.h \ @YANG_OUTPUT@/ipsec-sad.h \ @YANG_OUTPUT@/tunnel.h \ - @YANG_OUTPUT@/app-ztd.h + @YANG_OUTPUT@/app-ztd.h \ + @YANG_OUTPUT@/dhcp-agent.h BUILT_SOURCES = ${YANG_GENERATED_SRCS} ${YANG_GENERATED_HDRS} @@ -274,7 +277,8 @@ lib_LTLIBRARIES = \ libcpsclass_system-status.la \ libcpsclass_ipsec-sad.la \ libcpsclass_tunnel.la \ - libcpsclass_app-ztd.la + libcpsclass_app-ztd.la \ + libcpsclass_dhcp-agent.la AM_CPPFLAGS = -I@YANG_OUTPUT@ -I$(oldincludedir)/opx @@ -476,6 +480,9 @@ libcpsclass_tunnel_la_LIBADD = -lopx_cps_api_common libcpsclass_app_ztd_la_SOURCES = @YANG_OUTPUT@/app-ztd.cpp libcpsclass_app_ztd_la_LIBADD = -lopx_cps_api_common +libcpsclass_dhcp_agent_la_SOURCES = @YANG_OUTPUT@/dhcp-agent.cpp +libcpsclass_dhcp_agent_la_LIBADD = -lopx_cps_api_common + @YANG_OUTPUT@/%.h @YANG_OUTPUT@/%.cpp: @YANG_OUTPUT@/%-stamp; @: @YANG_OUTPUT@/%-stamp: %.yang @ rm -f @YANG_OUTPUT@/$*.cpp diff --git a/yang-models/dhcp-agent.yang b/yang-models/dhcp-agent.yang new file mode 100644 index 0000000..8e55270 --- /dev/null +++ b/yang-models/dhcp-agent.yang @@ -0,0 +1,360 @@ +module dhcp-agent { + + namespace "urn:ietf:params:xml:ns:yang:dhcp-agent"; + prefix dhcp-agent; + + import ietf-inet-types { + prefix inet; + } + import ietf-interfaces { + prefix if; + } + import dell-base-common { prefix "base-cmn"; } + import iana-if-type { prefix "ianaift"; } + + organization "Inocybe Technologies"; + + contact "Anton Ivanov "; + + description + "This module contains a set of definitions to control + a programmable Layer2 switch DHCP agent and/or DHCP Relay."; + + revision 2018-04-26 { + description "Initial revision."; + } + + typedef comparison-operation { + type enumeration { + enum "EQ" { + value 0; + } + enum "GE" { + value 1; + } + enum "LE" { + value 2; + } + enum "G" { + value 3; + } + enum "L" { + value 4; + } + enum "AND" { + value 5; + } + enum "OR" { + value 6; + } + enum "GLOB" { + description + "Return true regardless of values - intended for additions"; + value 7; + } + } + } + + typedef which-direction { + type enumeration { + enum "UP" { + description "To Server"; + value 0; + } + enum "DOWN" { + description "To Client"; + value 1; + } + } + } + grouping dhcp-option { + description "Format of DHCP options"; + leaf dhcp-option-code { + type uint8; + mandatory true; + description "DHCP Option Code"; + } + choice option-type { + case void-option { + } + case inet-option { + leaf inet { + type base-cmn:ip-address; + description "An IPv4 Address"; + } + } + case inet-list { + list inets { + key "order"; + description "A list of IPv4 Addresses"; + leaf order { + type uint8; + description "Dummy number used to order the list"; + } + leaf address { + type base-cmn:ip-address; + description "An IPv4 Address"; + } + } + } + case inet-paired-list { + list paired-inets { + key "order"; + description "A list of IPv4 Addresses"; + leaf order { + type uint8; + description "Dummy number used to order the list"; + } + leaf address-1 { + type base-cmn:ip-address; + description "An IPv4 Address"; + } + leaf address-2 { + type base-cmn:ip-address; + description "An IPv4 Address"; + } + } + } + case integer { + leaf int-value { + type uint32; + description "32 bit integer value"; + } + } + case short { + leaf short-value { + type uint16; + description "16 bit integer value"; + } + } + case short-list { + leaf-list short-value-list { + type uint16; + description "list of 16 bit integer values"; + } + } + case byte { + leaf byte-value { + type uint8; + description "8 bit integer value"; + } + } + case byte-list { + leaf-list byte-value-list { + type uint8; + description "List of 8 bit integer values"; + } + } + case string { + leaf-list string-value { + type string; + description "String option value"; + } + } + case relays { + list relay-option-values { + key "relay-option"; + description "A list of Relay Agent Options"; + leaf relay-option { + type uint8; + description "Relay Option Code"; + } + leaf value { + type string; + description "Relay Option Value"; + } + } + } + case client-identifier { + container ids { + leaf hardware-type { + type uint8; + description "Hardware Type"; + } + leaf string { + type string; + description "Hardware address"; + } + } + } + + case csr { + leaf csr { + type inet:ipv4-prefix; + description "IPv4 Prefix (leave the conversion to serialization)"; + } + } + case binary { + leaf bin-value { + type binary; + description "Catch-all for everything else which we do not know"; + } + } + /* + suboptions : hex encoded sub options + */ + } + } + + grouping dhcp-packet { + description "Format of DHCP Packet"; + leaf op { + type uint8; + description "BOOTP op"; + } + leaf htype { + type uint8; + description "Hardware Type"; + } + leaf hlen { + type uint8; + description "Hardware Address Length"; + } + leaf hops { + type uint8; + description "Relay Agent Hops"; + } + leaf xid { + type uint32; + description "Xid"; + } + leaf secs { + type uint16; + description "Seconds since the start of configuration"; + } + leaf flags { + type uint16; + description "Flags - Broadcast or Unicast for reply"; + } + leaf ciaddr { + type base-cmn:ip-address; + description "Client IP Address"; + } + leaf yiaddr { + type base-cmn:ip-address; + description "Your (client) IP address"; + } + leaf siaddr { + type base-cmn:ip-address; + description "Next Server address"; + } + leaf giaddr { + type base-cmn:ip-address; + description "Relay Address"; + } + leaf chaddr { + type binary; + description "Client Hardware Address"; + } + leaf sname { + type string; + description "Server Name"; + } + leaf file { + type string; + description "Boot File Name"; + } + list dhcp-options { + key "option-order"; + leaf option-order { + type uint8; + description "Dummy ordering field to order the list"; + } + uses dhcp-option; + } + } + + grouping comparison-data { + leaf operation { + type comparison-operation; + description "Operation for comparison"; + } + + leaf list-operation { + type comparison-operation; + description "Operation for comparison - list form options"; + } + + leaf direction { + type which-direction; + description "When to apply the processing"; + } + + uses dhcp-packet; + } + + + + /* + * Configuration data nodes + */ + + augment "/if:interfaces/if:interface" { + when "if:type = 'ianaift:l2vlan'"; + + leaf dhcp-server { + type base-cmn:ip-address; + description + "A Server to forward requests for this interface when + operating as a DHCP Relay. + If this leaf is null, the agent will change the requests + transparently before forwarding them at Layer 2."; + } + + leaf trusted { + type string; + description + "A trusted interface for forwarding requests which have been + snooped in MitM mode"; + } + list delete { + key "priority"; + description + "Options to delete + + The implementation scans the dhcp data and selects an + an option to delete. + + Specifying only the option code will delete + regardless of value and comparison operation. + + Specifying option values will use the + comparison-operation from op on the option data. + If the option data is a list, the operation will be + performed on all elements and accumulated according + to list-op. + If the comparison operation yields a true value, the + option will be deleted. + "; + leaf priority { + type uint32; + description "Defines the order in which the rules are executed"; + } + uses comparison-data; + + } + list add { + key "priority"; + description + "Options to add + The implementation scans the dhcp data using the same semantics as for + delete. If the search returns true, the list of additions is executed. + "; + leaf priority { + type uint32; + description "Defines the order in which the rules are executed"; + } + + uses comparison-data; + + list additions { + key "order"; + leaf order { + type uint32; + description "Defines the order in which the additions are processed"; + } + uses dhcp-packet; + } + } + } +} From 4abdb4081189ee615a244c8e2d19b1eca4e9adfa Mon Sep 17 00:00:00 2001 From: Anton Ivanov Date: Thu, 20 Dec 2018 08:57:19 +0000 Subject: [PATCH 2/3] Install pyang only if not present Signed-off-by: Anton Ivanov --- src/unit_test/run_test | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/unit_test/run_test b/src/unit_test/run_test index 38ec368..8bc5ccc 100644 --- a/src/unit_test/run_test +++ b/src/unit_test/run_test @@ -2,7 +2,9 @@ # Script to run unit test # -sudo pip install pyang +if ! which pyang >/dev/null 2>&1 ; then + sudo pip install pyang +fi pyang -f tree yang-models/*.yang -p ./ -Wnone From ee2261dc9ef274ae377cf0954f6b8d695251ee93 Mon Sep 17 00:00:00 2001 From: Anton Ivanov Date: Thu, 20 Dec 2018 08:57:37 +0000 Subject: [PATCH 3/3] Fix pyang warnings Fixes a number of pyang complaints regarding lack of decriptions. Signed-off-by: Anton Ivanov --- yang-models/dhcp-agent.yang | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/yang-models/dhcp-agent.yang b/yang-models/dhcp-agent.yang index 8e55270..2358dcf 100644 --- a/yang-models/dhcp-agent.yang +++ b/yang-models/dhcp-agent.yang @@ -20,8 +20,9 @@ module dhcp-agent { "This module contains a set of definitions to control a programmable Layer2 switch DHCP agent and/or DHCP Relay."; - revision 2018-04-26 { + revision 2018-12-20 { description "Initial revision."; + reference "TODO - OPX Specific model"; } typedef comparison-operation { @@ -48,27 +49,28 @@ module dhcp-agent { value 6; } enum "GLOB" { + value 7; description "Return true regardless of values - intended for additions"; - value 7; } } + description "Packet processing operands"; } typedef which-direction { type enumeration { enum "UP" { - description "To Server"; value 0; + description "To Server"; } enum "DOWN" { - description "To Client"; value 1; + description "To Client"; } } + description "Packet processing direction for rulesets."; } grouping dhcp-option { - description "Format of DHCP options"; leaf dhcp-option-code { type uint8; mandatory true; @@ -175,6 +177,7 @@ module dhcp-agent { type string; description "Hardware address"; } + description "DHCP Client Identifier"; } } @@ -190,10 +193,12 @@ module dhcp-agent { description "Catch-all for everything else which we do not know"; } } + description "DHCP Option type"; /* suboptions : hex encoded sub options */ } + description "Format of DHCP options"; } grouping dhcp-packet { @@ -261,6 +266,7 @@ module dhcp-agent { description "Dummy ordering field to order the list"; } uses dhcp-option; + description "DHCP Options in the packet"; } } @@ -281,6 +287,7 @@ module dhcp-agent { } uses dhcp-packet; + description "Pipeline operation - rules to apply to a DHCP Packet"; } @@ -354,7 +361,9 @@ module dhcp-agent { description "Defines the order in which the additions are processed"; } uses dhcp-packet; + description "List of options/values to inject into the packet"; } } + description "DHCP Agent control options for an interface"; } }