Class: Distem::Resource::VIface

Inherits:
Object
  • Object
show all
Defined in:
lib/distem/resource/viface.rb

Overview

Abstract representation of a virtual network interface

Defined Under Namespace

Classes: VTraffic

Constant Summary

@@ids =
0

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (VIface) initialize(name, vnode, default = false)

Create a new VIface

Attributes

  • name The name of the virtual network interface

  • vnode The VNode object describing the virtual node associated to this virtual network interface

  • default Specify if it has to be set as the default interface



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/distem/resource/viface.rb', line 121

def initialize(name,vnode,default = false)
  raise if name.empty? or not name.is_a?(String)

  @id = @@ids
  @name = name
  @vnode = vnode
  @address = IPAddress::IPv4.new("0.0.0.0/0")
  @macaddress = nil
  @vnetwork = nil
  @vinput = nil
  @voutput = nil
  @vroutes = []
  @@ids += 1
  @ifb = nil
  @filters = nil
  @default = default
end

Instance Attribute Details

- (Object) address (readonly)

The IP address of the network interface



98
99
100
# File 'lib/distem/resource/viface.rb', line 98

def address
  @address
end

- (Object) bridge

Bridge on with the viface is attached



112
113
114
# File 'lib/distem/resource/viface.rb', line 112

def bridge
  @bridge
end

- (Object) default (readonly)

Define if this interface is the vnode's default one



114
115
116
# File 'lib/distem/resource/viface.rb', line 114

def default
  @default
end

- (Object) id (readonly)

The unique identifier of the network interface



92
93
94
# File 'lib/distem/resource/viface.rb', line 92

def id
  @id
end

- (Object) ifb

The ifb device used by this viface



108
109
110
# File 'lib/distem/resource/viface.rb', line 108

def ifb
  @ifb
end

- (Object) latency_filters

Special rules that override all the virtual traffic



110
111
112
# File 'lib/distem/resource/viface.rb', line 110

def latency_filters
  @latency_filters
end

- (Object) macaddress

The mac address of the network interface



100
101
102
# File 'lib/distem/resource/viface.rb', line 100

def macaddress
  @macaddress
end

- (Object) name (readonly)

The name of the network interface



94
95
96
# File 'lib/distem/resource/viface.rb', line 94

def name
  @name
end

- (Object) vinput

The input VTraffic description



106
107
108
# File 'lib/distem/resource/viface.rb', line 106

def vinput
  @vinput
end

- (Object) vnetwork (readonly)

The VNetwork this interface is attached to (nil if none)



102
103
104
# File 'lib/distem/resource/viface.rb', line 102

def vnetwork
  @vnetwork
end

- (Object) vnode (readonly)

The VNode this network interface is associated with



96
97
98
# File 'lib/distem/resource/viface.rb', line 96

def vnode
  @vnode
end

- (Object) voutput

The output VTraffic description



104
105
106
# File 'lib/distem/resource/viface.rb', line 104

def voutput
  @voutput
end

Instance Method Details

- (Object) ==(viface)

Compare two VIfaces (based on their name)

Returns

Boolean value



196
197
198
# File 'lib/distem/resource/viface.rb', line 196

def ==(viface)
  viface.is_a?(VIface) and (@name == viface.name)
end

- (Object) attach(vnetwork, address)

Attach the virtual network interface to a virtual network specifying it's IP address

Attributes

  • vnetwork The VNetwork object

  • address The IPAddress object



143
144
145
146
147
# File 'lib/distem/resource/viface.rb', line 143

def attach(vnetwork,address)
  raise Lib::AlreadyExistingResourceError, @name if @vnetwork
  @vnetwork = vnetwork
  @address = address
end

- (Boolean) attached?

Check if the virtual network interface is connected to a virtual network

Returns

Boolean value

Returns:

  • (Boolean)


163
164
165
# File 'lib/distem/resource/viface.rb', line 163

def attached?
  @vnetwork != nil and @address != nil
end

- (Boolean) connected_to?(vnetwork)

Check if the virtual network interface is connected to a specified virtual network

Attributes

  • vnetwork The VNetwork object describing the virtual network

Returns

Boolean value

Returns:

  • (Boolean)


173
174
175
176
# File 'lib/distem/resource/viface.rb', line 173

def connected_to?(vnetwork)
  raise unless vnetwork.is_a?(VNetwork)
  return (vnetwork ? vnetwork.address.include?(@address) : false)
end

- (Object) detach

Detach the virtual network interface from the VNetwork it's connected to



150
151
152
153
154
155
156
157
158
# File 'lib/distem/resource/viface.rb', line 150

def detach()
  if attached?
    @vnetwork.remove_vnode(@vnode,false)
    @vnetwork = nil
    @vinput = nil
    @voutput = nil
    @address = IPAddress::IPv4.new("0.0.0.0/0")
  end
end

- (Object) reset_vtraffic

Reset the virtual traffic of this virtual network interface



179
180
181
182
# File 'lib/distem/resource/viface.rb', line 179

def reset_vtraffic()
  @vinput = nil
  @voutput = nil
end

- (Boolean) vtraffic?

Check if a VTraffic is specified for this virtual network interface

Returns

Boolean value

Returns:

  • (Boolean)


188
189
190
# File 'lib/distem/resource/viface.rb', line 188

def vtraffic?
  return (@vinput or @voutput)
end