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



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

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



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

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



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

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



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

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



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

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