Skip to content

Commit

Permalink
f-93: Corrects test and config file generation
Browse files Browse the repository at this point in the history
Signed-off-by: Aleix Ramírez <[email protected]>
  • Loading branch information
aleixrm committed Nov 27, 2024
1 parent 6cf6ccc commit b598a84
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func main() {
}

conv, err := c.Exchange("lo",
dhcpv4.WithClientIP(net.ParseIP("127.0.0.1")),
dhcpv4.WithHwAddr(mac))
for _, p := range conv {
log.Print(p.Summary())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ func (p *PluginState) Handler4(req, resp *dhcpv4.DHCPv4) (*dhcpv4.DHCPv4, bool)
ipFromMAC, ok, err := p.checkMACPrefix(macAddress)
if err != nil {
log.Errorf("MAC2IP lease failed for mac %v: %v", macAddress.String(), err)
// return nack to the client
resp.Options.Update(dhcpv4.OptMessageType(dhcpv4.MessageTypeNak))
return resp, true
}
if ok {
Expand All @@ -94,9 +92,6 @@ func (p *PluginState) Handler4(req, resp *dhcpv4.DHCPv4) (*dhcpv4.DHCPv4, bool)
ip, err := p.allocator.Allocate(ipToAllocate)
if err != nil {
log.Errorf("Could not allocate IP for MAC %s: %v", req.ClientHWAddr.String(), err)
resp.Options.Update(dhcpv4.OptMessageType(dhcpv4.MessageTypeNak))
// return nack to the client
resp.Options.Update(dhcpv4.OptMessageType(dhcpv4.MessageTypeNak))
return resp, true
}

Expand All @@ -105,8 +100,6 @@ func (p *PluginState) Handler4(req, resp *dhcpv4.DHCPv4) (*dhcpv4.DHCPv4, bool)
log.Warnf("Allocated IP %s for MAC %s does not match the requested IP %s", ip.IP.String(), req.ClientHWAddr.String(), ipToAllocate.IP.String())
//revert the allocation of the undesired IP
p.allocator.Free(ip)
// return nack to the client
resp.Options.Update(dhcpv4.OptMessageType(dhcpv4.MessageTypeNak))
return resp, true
}

Expand Down Expand Up @@ -208,11 +201,13 @@ func setupRange(args ...string) (handler.Handler4, error) {
var excludedIPs string
var macPrefix string

pflag.StringVar(&excludedIPs, "excluded-ips", "", "Comma-separated list of excluded IP addresses")
pflag.BoolVar(&p.enableMAC2IP, "mac2ip", false, "Enables MAC to IP address mapping")
pflag.StringVar(&macPrefix, "mac-prefix", "02:00", "2-byte MAC prefix for MAC to IP address mapping. Defaults to [02:00]")
pluginFlags := pflag.NewFlagSet("onerange", pflag.ExitOnError)

pflag.CommandLine.Parse(optionalArgs)
pluginFlags.StringVar(&excludedIPs, "excluded-ips", "", "Comma-separated list of excluded IP addresses")
pluginFlags.BoolVar(&p.enableMAC2IP, "mac2ip", false, "Enables MAC to IP address mapping")
pluginFlags.StringVar(&macPrefix, "mac2ip-prefix", "02:00", "2-byte MAC prefix for MAC to IP address mapping")

pluginFlags.Parse(optionalArgs)

if p.enableMAC2IP && macPrefix != "" {
p.MACPrefix, err = parseMACPrefix(macPrefix)
Expand Down
8 changes: 6 additions & 2 deletions appliances/VRouter/DHCP4v2/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,13 @@ def generate_config(basedir, vars)
end

def generate_range_config(nic, nic_data)
lease_range = nic_data[:range].gsub('-', ' ')
lease_range = nic_data[:range]&.gsub('-', ' ')
excluded_ips_str = ([nic_data[:address]] + nic_data[:vips]).join(',')
return "leases-#{nic}.sqlite3 #{lease_range} #{ONEAPP_VNF_DHCP4_LEASE_TIME}s #{excluded_ips_str}"
range_config = "leases-#{nic}.sqlite3 #{lease_range} #{ONEAPP_VNF_DHCP4_LEASE_TIME}s"
range_config += " --excluded-ips #{excluded_ips_str}" unless excluded_ips_str.empty?
range_config += " --mac2ip" if ONEAPP_VNF_DHCP4_MAC2IP_ENABLED
range_config += " --mac2ip-prefix #{ONEAPP_VNF_DHCP4_MAC2IP_MACPREFIX}" if ONEAPP_VNF_DHCP4_MAC2IP_ENABLED
return range_config
end

def install(initdir: '/etc/init.d')
Expand Down
9 changes: 6 additions & 3 deletions appliances/VRouter/DHCP4v2/tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ def clear_vars(object)
- mtu: 1111
- router: 1.2.3.4
- netmask: 255.255.0.0
- range: leases-eth1.sqlite3 20.30.0.2 20.30.255.254 3600s 20.30.40.50,20.30.40.55
- range: leases-eth1.sqlite3 20.30.0.2 20.30.255.254 3600s --excluded-ips 20.30.40.50,20.30.40.55
--mac2ip --mac2ip-prefix 02:00
- onelease:
eth2:
server4:
Expand All @@ -116,7 +117,8 @@ def clear_vars(object)
- mtu: 2222
- router: 30.40.50.1
- netmask: 255.0.0.0
- range: leases-eth2.sqlite3 30.40.50.64 30.40.50.68 3600s 30.40.50.60
- range: leases-eth2.sqlite3 30.40.50.64 30.40.50.68 3600s --excluded-ips 30.40.50.60
--mac2ip --mac2ip-prefix 02:00
- onelease:
eth3:
server4:
Expand All @@ -129,7 +131,8 @@ def clear_vars(object)
- mtu: 3333
- router: 40.50.60.1
- netmask: 255.255.255.0
- range: leases-eth3.sqlite3 40.50.60.2 40.50.60.254 3600s 40.50.60.70
- range: leases-eth3.sqlite3 40.50.60.2 40.50.60.254 3600s --excluded-ips 40.50.60.70
--mac2ip --mac2ip-prefix 02:00
- onelease:
ONELEASE_CONF

Expand Down

0 comments on commit b598a84

Please sign in to comment.