diff --git a/DHCP/vrf-relay/README.md b/DHCP/vrf-relay/README.md new file mode 100644 index 0000000..9633a46 --- /dev/null +++ b/DHCP/vrf-relay/README.md @@ -0,0 +1,13 @@ +# VRF-aware DHCP relaying + +This directory contains *netlab* topology file for a simple VRF-aware DHCP relaying scenario. + +![DHCP relaying topology](dhcp-relay.png) + +After starting the lab, the *user* device should get DHCP-assigned IP address on its lab-facing interface. + +## Changing Device Types + +This topology can be used with Cisco IOSv or Arista EOSv. To test it with other devices, add custom configuration template to `dhcp-relay` directory. + +The easiest way to change the device types is to edit the topology file. You could also use the **netlab up** [CLI arguments](https://netsim-tools.readthedocs.io/en/latest/netlab/up.html#usage) -- to change the DHCP relay device type, use `-s nodes.relay.device=xxx` CLI argument. diff --git a/DHCP/vrf-relay/dhcp-client/ios.j2 b/DHCP/vrf-relay/dhcp-client/ios.j2 new file mode 100644 index 0000000..1c868db --- /dev/null +++ b/DHCP/vrf-relay/dhcp-client/ios.j2 @@ -0,0 +1,5 @@ +{% for intf in interfaces if intf.dhcp.client is defined and intf.dhcp.client %} +interface {{ intf.ifname }} + no ip address + ip address dhcp +{% endfor %} \ No newline at end of file diff --git a/DHCP/vrf-relay/dhcp-relay.png b/DHCP/vrf-relay/dhcp-relay.png new file mode 100644 index 0000000..be4afd0 Binary files /dev/null and b/DHCP/vrf-relay/dhcp-relay.png differ diff --git a/DHCP/vrf-relay/dhcp-relay/eos.j2 b/DHCP/vrf-relay/dhcp-relay/eos.j2 new file mode 100644 index 0000000..4799780 --- /dev/null +++ b/DHCP/vrf-relay/dhcp-relay/eos.j2 @@ -0,0 +1,11 @@ +{% for intf in interfaces if intf.dhcp.server is defined and intf.vrf is defined %} +{% if loop.first %} +ip dhcp relay information option +{% endif %} +{% endfor %} +! +{% for intf in interfaces if intf.dhcp.server is defined %} +{% set helper = hostvars[intf.dhcp.server].loopback.ipv4|ipaddr('address') %} +interface {{ intf.ifname }} + ip helper-address {{ helper }}{% if intf.vrf is defined %} vrf default{% endif %} +{% endfor %} diff --git a/DHCP/vrf-relay/dhcp-relay/ios.j2 b/DHCP/vrf-relay/dhcp-relay/ios.j2 new file mode 100644 index 0000000..8e97426 --- /dev/null +++ b/DHCP/vrf-relay/dhcp-relay/ios.j2 @@ -0,0 +1,15 @@ +{% for intf in interfaces if intf.dhcp.server is defined and intf.vrf is defined %} +{% if loop.first %} +ip dhcp relay information option vpn +{% endif %} +{% endfor %} +! +{% for intf in interfaces if intf.dhcp.server is defined %} +{% set helper = hostvars[intf.dhcp.server].loopback.ipv4|ipaddr('address') %} +interface {{ intf.ifname }} +{% if intf.vrf is defined %} + ip helper-address global {{ helper }} +{% else %} + ip helper-address {{ helper }} +{% endif %} +{% endfor %} \ No newline at end of file diff --git a/DHCP/vrf-relay/dhcp-server.j2 b/DHCP/vrf-relay/dhcp-server.j2 new file mode 100644 index 0000000..5189852 --- /dev/null +++ b/DHCP/vrf-relay/dhcp-server.j2 @@ -0,0 +1,23 @@ +logging buffered +no service timestamp debug +! +do debug ip dhcp server packet +do debug ip dhcp server event +! +{% for h,v in hostvars.items() %} +{% for intf in v.interfaces if intf.dhcp.server is defined and intf.ipv4 is defined %} +ip dhcp excluded-address {% if intf.vrf is defined %}vrf {{ intf.vrf }} {% endif %}{{ intf.ipv4|ipaddr('address') }} +{% endfor %} +{% endfor %} +! +{% for h,v in hostvars.items() %} +{% for intf in v.interfaces if intf.dhcp.server is defined and intf.ipv4 is defined %} +! +ip dhcp pool p_{{ intf.ipv4|ipaddr('network') }} +{% if intf.vrf is defined %} + vrf {{ intf.vrf }} +{% endif %} + network {{ intf.ipv4|ipaddr('network') }} {{ intf.ipv4|ipaddr('netmask') }} + default-router {{ intf.ipv4|ipaddr('address') }} +{% endfor %} +{% endfor %} \ No newline at end of file diff --git a/DHCP/vrf-relay/graph.dot b/DHCP/vrf-relay/graph.dot new file mode 100644 index 0000000..0271fb0 --- /dev/null +++ b/DHCP/vrf-relay/graph.dot @@ -0,0 +1,21 @@ +graph { + bgcolor="transparent" + node [shape=box, style="rounded,filled" fontname=Verdana] + edge [fontname=Verdana labelfontsize=10 labeldistance=1.5] + "srv" [ + label=10.0.0.1/32> + fillcolor="#ff9f01" + ] + "relay" [ + label=10.0.0.2/32> + fillcolor="#ff9f01" + ] + "user" [ + label=10.0.0.3/32> + fillcolor="#ff9f01" + ] + "relay" -- "srv" [ width=5 ] + "relay_2" [style=filled fillcolor="#ff8080" fontsize=11 label=<172.16.0.0/24
VRF client>] + "user" -- "relay_2" [ color="#800000" width=5 ] + "relay" -- "relay_2" [ color="#800000" width=5 ] +} diff --git a/DHCP/vrf-relay/topology.yml b/DHCP/vrf-relay/topology.yml new file mode 100644 index 0000000..ac6ad35 --- /dev/null +++ b/DHCP/vrf-relay/topology.yml @@ -0,0 +1,41 @@ +message: | + This topology sets up a simple network using VRF-aware DHCP relay + functionality. It includes a DHCP server (running on Cisco + IOSv), DHCP client (also on Cisco IOSv) and an intermediate + node. + +defaults.attributes: + link.dhcp: + client: bool + server: str + +defaults.device: iosv + +groups: + dhcp_server: + members: [ srv ] + module: [ ospf ] + config: [ dhcp-server ] + device: csr + dhcp_client: + members: [ user ] + config: [ dhcp-client ] + device: iosv + switch: + members: [ relay ] + module: [ ospf,vrf ] + config: [ dhcp-relay ] + +vrfs: + client: + +nodes: [ srv, relay, user ] + +links: +- relay-srv +- user: + dhcp.client: True + relay: + dhcp.server: srv + type: lan + vrf: client diff --git a/DHCP/vrf-relay/vrf-dhcp-relay.png b/DHCP/vrf-relay/vrf-dhcp-relay.png new file mode 100644 index 0000000..326f91c Binary files /dev/null and b/DHCP/vrf-relay/vrf-dhcp-relay.png differ