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
# File 'lib/packetgen/config.rb', line 24

def initialize
  @default_iface = PacketGen.default_iface || PacketGen.loopback_iface
  @hwaddr = {}
  @ipaddr = {}
  @ip6addr = {}

  initialize_local_addresses
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



36
37
38
# File 'lib/packetgen/config.rb', line 36

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



50
51
52
# File 'lib/packetgen/config.rb', line 50

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



43
44
45
# File 'lib/packetgen/config.rb', line 43

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