Class: PacketGen::Config

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/packetgen/config.rb

Overview

Config class to provide config object to pgconsole

Author:

  • Sylvain Daubert

  • Kent ‘picat’ Gruber

Since:

  • 1.4.1

  • 2.1.3 Config is singleton

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.

Since:

  • 1.4.1

  • 2.1.3 Config is singleton



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/packetgen/config.rb', line 24

def initialize
  @default_iface = Interfacez.default || Interfacez.loopback
  @hwaddr = {}
  @ipaddr = {}
  @ip6addr = {}

  Interfacez.all do |iface_name|
    @hwaddr[iface_name] = Interfacez.mac_address_of(iface_name)
    @ipaddr[iface_name] = Interfacez.ipv4_address_of(iface_name)
    @ip6addr[iface_name] = Interfacez.ipv6_addresses_of(iface_name)
  end
end

Instance Attribute Details

#default_ifaceString (readonly)

Default network interface

Returns:

  • (String)

Since:

  • 1.4.1

  • 2.1.3 Config is singleton



22
23
24
# File 'lib/packetgen/config.rb', line 22

def default_iface
  @default_iface
end

Instance Method Details

#hwaddr(iface = nil) ⇒ String

Get MAC address for given network interface

Parameters:

  • iface (String, nil) (defaults to: nil)

    network interface. If nil, use default one.

Returns:

  • (String)

Since:

  • 1.4.1

  • 2.1.3 Config is singleton



40
41
42
# File 'lib/packetgen/config.rb', line 40

def hwaddr(iface=nil)
  @hwaddr[iface || @default_iface]
end

#ip6addr(iface = nil) ⇒ Array<String>

Get IPv6 addresses for given network interface

Parameters:

  • iface (String, nil) (defaults to: nil)

    network interface. If nil, use default one.

Returns:

  • (Array<String>)

Since:

  • 1.4.1

  • 2.1.3 Config is singleton



54
55
56
# File 'lib/packetgen/config.rb', line 54

def ip6addr(iface=nil)
  @ip6addr[iface || @default_iface]
end

#ipaddr(iface = nil) ⇒ String

Get IP address for given network interface

Parameters:

  • iface (String, nil) (defaults to: nil)

    network interface. If nil, use default one.

Returns:

  • (String)

Since:

  • 1.4.1

  • 2.1.3 Config is singleton



47
48
49
# File 'lib/packetgen/config.rb', line 47

def ipaddr(iface=nil)
  @ipaddr[iface || @default_iface]
end