Sha256: 7b21deed588ea96a9776578e817c325221844792cba7ec6e5d28d9f41239a575

Contents?: true

Size: 1.73 KB

Versions: 3

Compression:

Stored size: 1.73 KB

Contents

#
# Copyright (C) 2008-2012 NEC Corporation
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2, as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#


require "trema/action"


module Trema
  #
  # An action to modify the VLAN ID of a packet.
  #
  class SetVlanVid < Action
    attr_reader :vlan_id


    #
    # 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.
    #
    # @example
    #   ActionSetVlanVid.new( vlan_id )
    #
    # @param [Integer] vlan_id
    #   the VLAN ID to set to. Only the lower 12-bits are used.
    #
    # @raise [ArgumentError] if vlan_id not within 1 and 4096 inclusive.
    # @raise [TypeError] if vlan_id is not an Integer.
    #
    def initialize vlan_id
      if not vlan_id.is_a?( Integer )
        raise TypeError, "VLAN ID argument must be an Integer"
      end
      if not ( vlan_id >= 1 and vlan_id <= 4096 )
        raise ArgumentError, "Valid VLAN ID values between 1 to 4096 inclusive"
      end
      @vlan_id = vlan_id
    end
  end


  ActionSetVlanVid = SetVlanVid
end


### Local variables:
### mode: Ruby
### coding: utf-8-unix
### indent-tabs-mode: nil
### End:

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
trema-0.2.5 ruby/trema/set-vlan-vid.rb
trema-0.2.4 ruby/trema/set-vlan-vid.rb
trema-0.2.3 ruby/trema/set-vlan-vid.rb