Class: Trema::NetworkComponent

Inherits:
Object
  • Object
show all
Defined in:
ruby/trema/network-component.rb

Overview

The base class of objects appears in the Trema DSL. e.g., host, switch, link etc.

Direct Known Subclasses

App, Host, Link, Netns, OpenflowSwitch, PacketinFilter, SwitchManager

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.instancesArray

Returns the ‘name’ => object hash DB of instances

Examples:

p App.instances
#=> {"trema tetris"=>#<App:0xb73c9328>, ...}

Returns:



40
41
42
# File 'ruby/trema/network-component.rb', line 40

def instances
  @instances
end

Class Method Details

.[](name) ⇒ Object

Looks up a instance DB by its name

Examples:

ttetris = TremaTetris.new
ttetris.name = "trema tetris"

App.add ttetris

App[ "trema tetris" ] => ttetris

Returns:

  • (Object)

    the associated object



105
106
107
# File 'ruby/trema/network-component.rb', line 105

def self.[] name
  instances[ name ]
end

.add(object) ⇒ Object

Inserts a object to instance DB

Examples:

ttetris = TremaTetris.new
ttetris.name = "trema tetris"

App.add ttetris

Parameters:

  • object (Object, #name)

Returns:

  • (Object)

    the added object



140
141
142
# File 'ruby/trema/network-component.rb', line 140

def self.add object
  instances[ object.name ] = object
end

.clearObject



66
67
68
# File 'ruby/trema/network-component.rb', line 66

def self.clear
  instances.clear
end

.each(&block) ⇒ Array

Iterates over the list of instances

Examples:

App.each do | each |
  p each.name
end

Returns:

  • (Array)

    the list of instances



83
84
85
86
87
# File 'ruby/trema/network-component.rb', line 83

def self.each &block
  instances.values.each do | each |
    block.call each
  end
end

.inherited(subclass) ⇒ undefined

Called implicitly when inherited

Examples:

#
# The following calls inherited() implicitly
# then creates an instance DB of App object.
#
class App < Trmea::NetworkComponent
  attr_accessor :name
end

Returns:

  • (undefined)


60
61
62
# File 'ruby/trema/network-component.rb', line 60

def self.inherited subclass
  subclass.instances ||= OrderedHash.new
end

.sizeNumber

Returns the number of instances.

Examples:

App.size  #=> 3

Returns:

  • (Number)

    the number of instances



120
121
122
# File 'ruby/trema/network-component.rb', line 120

def self.size
  instances.values.size
end