Skip to content

Commit

Permalink
VRF-aware DHCP relay
Browse files Browse the repository at this point in the history
  • Loading branch information
ipspace committed Mar 6, 2023
1 parent 87127d0 commit 02e53c7
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 0 deletions.
13 changes: 13 additions & 0 deletions DHCP/vrf-relay/README.md
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 5 additions & 0 deletions DHCP/vrf-relay/dhcp-client/ios.j2
Original file line number Diff line number Diff line change
@@ -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 %}
Binary file added DHCP/vrf-relay/dhcp-relay.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions DHCP/vrf-relay/dhcp-relay/eos.j2
Original file line number Diff line number Diff line change
@@ -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 %}
15 changes: 15 additions & 0 deletions DHCP/vrf-relay/dhcp-relay/ios.j2
Original file line number Diff line number Diff line change
@@ -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 %}
23 changes: 23 additions & 0 deletions DHCP/vrf-relay/dhcp-server.j2
Original file line number Diff line number Diff line change
@@ -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 %}
21 changes: 21 additions & 0 deletions DHCP/vrf-relay/graph.dot
Original file line number Diff line number Diff line change
@@ -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=<srv [iosv]<br /><sub>10.0.0.1/32</sub>>
fillcolor="#ff9f01"
]
"relay" [
label=<relay [iosv]<br /><sub>10.0.0.2/32</sub>>
fillcolor="#ff9f01"
]
"user" [
label=<user [iosv]<br /><sub>10.0.0.3/32</sub>>
fillcolor="#ff9f01"
]
"relay" -- "srv" [ width=5 ]
"relay_2" [style=filled fillcolor="#ff8080" fontsize=11 label=<172.16.0.0/24<br />VRF client>]
"user" -- "relay_2" [ color="#800000" width=5 ]
"relay" -- "relay_2" [ color="#800000" width=5 ]
}
41 changes: 41 additions & 0 deletions DHCP/vrf-relay/topology.yml
Original file line number Diff line number Diff line change
@@ -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
Binary file added DHCP/vrf-relay/vrf-dhcp-relay.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 02e53c7

Please sign in to comment.