Class: Pio::SetVlanVid

Inherits:
SetVlan show all
Defined in:
lib/pio/set_vlan_vid.rb

Overview

An action to modify the VLAN ID of a packet.

Instance Method Summary collapse

Methods inherited from SetVlan

def_format, read

Constructor Details

#initialize(number) ⇒ SetVlanVid

Creates an action to modify the VLAN ID of a packet. The VLAN ID is 16-bits long but the actual VID (VLAN Identifier) of the IEEE 802.1Q frame is 12-bits.

Examples:

ActionSetVlanVid.new(number)

Parameters:

  • number (Integer)

    the VLAN ID to set to. Only the lower 12-bits are used.

Raises:

  • (ArgumentError)

    if vlan_id not within 1 and 4095 inclusive.

  • (TypeError)

    if vlan_id is not an Integer.



20
21
22
23
24
25
26
27
28
# File 'lib/pio/set_vlan_vid.rb', line 20

def initialize(number)
  vlan_id = number.to_i
  unless vlan_id >= 1 && vlan_id <= 4095
    fail ArgumentError, 'VLAN ID must be between 1 and 4095 inclusive'
  end
  @format = Format.new(vlan_id: vlan_id)
rescue NoMethodError
  raise TypeError, 'VLAN ID must be an Integer.'
end