Class: Distem::TopologyStore::SimgridReader

Inherits:
TopologyReader show all
Defined in:
lib/distem/topologystore/simgridreader.rb

Overview

Class that allow to load a configuration from an XML simgrid input. See “simgrid.gforge.inria.fr/files/simgrid.dtd” for more information about the input format. FIXME: document each method to explain how the translation is done

Constant Summary

IPHACKROOT =
'10.144'
@@iphack =
0

Instance Method Summary (collapse)

Constructor Details

- (SimgridReader) initialize(image)

Create a new SimgridReader specifying the path to an image (see Resource::FileSystem) to use for the virtual nodes

Attributes

  • image The path to a -compressed and bootstrapped- image (String)



15
16
17
18
# File 'lib/distem/topologystore/simgridreader.rb', line 15

def initialize(image)
  super()
  @image = image
end

Instance Method Details

- (Object) parse(inputstr)

Parse a simgrid XML string value that represents the virtual environment.

Attributes

  • inputstr The simgrid XML input (String)

Returns

Hash object that describes the platform (see Lib::Validator)



26
27
28
29
30
31
# File 'lib/distem/topologystore/simgridreader.rb', line 26

def parse(inputstr)
  result = {}
  xmldoc = REXML::Document.new(inputstr)
  result = parse_platform(xmldoc,result)
  return result
end

- (Object) parse_cluster(xmldoc, result, tmp = {})

See the parse_platform method documentation



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/distem/topologystore/simgridreader.rb', line 71

def parse_cluster(xmldoc,result,tmp={})
  netname = xmldoc.attribute('id').to_s
  result['vnetworks'] << {
    'name' => netname,
    'address' => "#{IPHACKROOT}.#{@@iphack}.0/24"
  }
  @@iphack += 1

  vnode = nil
  create_vnode = Proc.new {
    vnode = {
      'name' => nil,
      'vifaces' => [{
        'name' => 'if0',
        'vnetwork' => netname,
        'vinput' => nil,
        'voutput' => {
          'direction' => 'OUTPUT',
          'properties' => [
            { 'type' => 'bandwidth', 'rate' => xmldoc.attribute('bw').to_s.to_f.to_s + 'bps' },
            { 'type' => 'latency', 'delay' => xmldoc.attribute('lat').to_s.to_f.to_s + 's' },
          ]
        }
      }],
      'vfilesystem' =>  {
        'image' => @image,
        'shared' => true
      }
    }
  }

  create_vnode.call
  defaultgw = vnode
  defaultgw['name'] = netname + '_gw'
  defaultgw['vifaces'][0]['voutput'] = nil
  defaultgw['gateway'] = true
  result['vnodes'] << defaultgw

  tmp['gateways'] = [] unless tmp['gateways']
  gw = {
    'name' => defaultgw['name'],
    'bw' => nil,
    'lat' => nil,
    'ifnb' => 1
  }
  tmp['gateways'] << gw
  tmp['networks'] = [] unless tmp['networks']
  tmp['networks'] << {
    'name' => netname,
    'defaultgw' => gw,
  }


  lbound,ubound = xmldoc.attribute('radical').to_s.split('-')
  (lbound..ubound).each do |no|
    create_vnode.call
    vnode['name'] = xmldoc.attribute('prefix').to_s + no.to_s + xmldoc.attribute('sufix').to_s
    result['vnodes'] << vnode
  end

end

See the parse_platform method documentation



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/distem/topologystore/simgridreader.rb', line 134

def parse_link(xmldoc,result,tmp={})
  switch = xmldoc.attribute('sharing_policy')
  if switch and switch.to_s == 'FATPIPE'
    nodename = xmldoc.attribute('id').to_s
    result['vnodes'] << {
      'name' => nodename,
      'vifaces' => [],
      'gateway' => true,
      'vfilesystem' => {
        'image' => @image,
        'shared' => true
      }
    }
    tmp['switches'] = [] unless tmp['switches']
    tmp['switches'] << { 
      'name' => nodename,
      'bw' => xmldoc.attribute('bandwidth').to_s.to_f.to_s + 'bps',
      'lat' => xmldoc.attribute('latency').to_s.to_f.to_s + 's',
      'ifnb' => 0,
    }
  end
end

See the parse_platform method documentation



287
288
289
290
291
292
293
294
295
296
297
298
299
# File 'lib/distem/topologystore/simgridreader.rb', line 287

def parse_link_ctn(xmldoc,result,tmp)
  name = xmldoc.attribute('id').to_s
  switch = tmp['switches'].select{ |sw| sw['name'] == name }[0] if tmp['switches']
  ret = true
  if switch
    ret = switch
  elsif name == '$dst'
    ret = false
  else
    ret = true
  end
  return ret
end

- (Object) parse_platform(xmldoc, result, tmp = {})

Parse the <platform> XML field. All the “parse_” methods are working the same way, parsing the associated XML field that represents a simgrid resource.

Attributes

  • xmldoc The REXML::Element object that describes the field

  • result The Hash output result to write the result to

  • tmp An object used to pass arguments through the methods

Returns

Hash object that describes the virtual platform (see Lib::Validator)



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/distem/topologystore/simgridreader.rb', line 41

def parse_platform(xmldoc,result,tmp={})
  raise Lib::NotImplementedError unless xmldoc.root.attributes['version'] == '2'
  result['vplatform'] = {}
  result['vplatform']['vnodes'] = []
  result['vplatform']['vnetworks'] = []

  # Create all the nodes contained in a cluster
  xmldoc.elements.each("*/cluster") do |cluster|
    parse_cluster(cluster,result['vplatform'],tmp)
  end

  # Create virtual switchss (VNodes in gateway mode)
  xmldoc.elements.each("*/link") do |cluster|
    parse_link(cluster,result['vplatform'],tmp)
  end

  # Connect virtual switches
  xmldoc.elements.each("*/link") do |cluster|
    parse_switch(cluster,result['vplatform'],tmp)
  end

  # Connect the networks to the switches
  xmldoc.elements.each("*/route:multi") do |cluster|
    parse_route_multi(cluster,result['vplatform'],tmp)
  end

  return result
end

- (Object) parse_route_multi(xmldoc, result, tmp = {})

See the parse_platform method documentation



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/distem/topologystore/simgridreader.rb', line 202

def parse_route_multi(xmldoc,result,tmp={})
  srcnetstr = xmldoc.attribute('src').to_s
  dstnetstr = xmldoc.attribute('dst').to_s

  # >>> TODO: Create VRoute with dst instead of using vroutes_complete
  srcnet = tmp['networks'].select{ |net| net['name'] == srcnetstr }[0]
  dstnet = tmp['networks'].select{ |net| net['name'] == dstnetstr }[0]
  if srcnet
    cnt = 0
    elems = []
    switches = false
    elems << srcnet['defaultgw']
    xmldoc.elements.each('link:ctn') do |link|
      ret = parse_link_ctn(link,result,tmp)
      if ret == true
        cnt += 1
      elsif ret.is_a?(Hash)
        switches = true
        elems << ret
      end
    end
    elems << dstnet['defaultgw'] if dstnet

    elem = {}
    network1 = ''
    network2 = ''
    connect_elem = Proc.new {
      vnode = result['vnodes'].select{ |node| node['name'] == elem['name'] }[0]
      if network1 < network2
        networkname = network2 + '-' + network1
      else
        networkname = network1 + '-' + network2
      end

      # Create vnetwork
      newnet = result['vnetworks'].select { |net| net['name'] == networkname }
      if !newnet or newnet.empty?
        result['vnetworks'] << {
          'name' => networkname,
          'address' => "#{IPHACKROOT}.#{@@iphack}.0/24"
        }
        @@iphack += 1
      end

      # Create viface
      viface = vnode['vifaces'].select{ |iface| iface['vnetwork'] == networkname }[0]
      unless viface
        viface = {
          'name' => 'if' + elem['ifnb'].to_s,
          'vnetwork' => networkname,
          'vinput' => nil,
        }

        if elem['lat'] or elem['bw']
          viface['voutput'] = {
            'direction' => 'OUTPUT',
            'properties' => [
              { 'type' => 'bandwidth', 'rate' => elem['bw'] },
              { 'type' => 'latency', 'delay' => elem['lat'] },
            ]
          }
        else
          viface['voutput'] = nil
        end

        vnode['vifaces'] << viface
        elem['ifnb'] += 1
      end
    }

    if cnt == 1 or switches
      (1..(elems.size-1)).each do |i|
        network1 = elems[i-1]['name']
        network2 = elems[i]['name']
        elem = elems[i-1]
        connect_elem.call
        elem = elems[i]
        connect_elem.call
      end
    end

  end
end

- (Object) parse_switch(xmldoc, result, tmp = {})

See the parse_platform method documentation



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/distem/topologystore/simgridreader.rb', line 158

def parse_switch(xmldoc,result,tmp={})
  return nil unless tmp['switches']
  completename = xmldoc.attribute('id').to_s
  name1,name2 = completename.split('_')
  switch1 = tmp['switches'].select{ |switch| switch['name'].split('_sw')[0] == name1 }[0]
  switch2 = tmp['switches'].select{ |switch| switch['name'].split('_sw')[0] == name2 }[0]
  if switch1 and switch2
    bw = xmldoc.attribute('bandwidth').to_s.to_f.to_s + 'bps'
    lat = xmldoc.attribute('latency').to_s.to_f.to_s + 's'

    # Create vnetwork
    result['vnetworks'] << {
      'name' => completename,
      'address' => "#{IPHACKROOT}.#{@@iphack}.0/24"
    }
    @@iphack += 1

    switch = {}
    block = Proc.new {
      vnode = result['vnodes'].select{ |node| node['name'] == switch['name'] }[0]
      vnode['vifaces'] << {
        'name' => 'if' + switch['ifnb'].to_s,
        'vnetwork' => completename,
        'vinput' => nil,
        'voutput' => {
          'direction' => 'OUTPUT',
          'properties' => [
            { 'type' => 'bandwidth', 'rate' => bw },
            { 'type' => 'latency', 'delay' => lat },
          ]
        }
      }
      switch['ifnb'] += 1
    }
    # Connect switch1 to network
    switch = switch1
    block.call
    # Connect switch2 to network
    switch = switch2
    block.call
  end
end