Skip to content

Instantly share code, notes, and snippets.

@nickkaranatsios
Last active December 14, 2015 13:58
Show Gist options
  • Save nickkaranatsios/5097049 to your computer and use it in GitHub Desktop.
Save nickkaranatsios/5097049 to your computer and use it in GitHub Desktop.
vlinks

Currently trema-switch configuration looks like the following:

trema_switch( "lsw" ) {
  datapath_id "0xabc"
  ports "trema0-0,trema1-0"
}

vhost ("host1") {
  ip "192.168.0.1"
  netmask "255.255.0.0"
  mac "00:00:00:01:00:01"
}

vhost ("host2") {
  ip "192.168.0.2"
  netmask "255.255.0.0"
  mac "00:00:00:01:00:02"
}

link "host1", "lsw"
link "host2", "lsw"

In link.rb the link name is hardcoded to trema name. I would like to use as link names trema-switch's ports attribute.
Is there a simple way of achieving this somehow copy those values to @stanza or?

@yasuhito
Copy link

yasuhito commented Mar 6, 2013

Maybe you can determine the ports attribute of trema_switch automatically as follows. This uses Trema::Link.instances (from Trema::NetworkComponent) to get known links list.

# In ruby/trema/dsl/trema-switch.rb,

ports = 
  Trema::Link.instances.values.select do | each |
    each.peers.include? @name  # This value is "lsw" in the above case.
  end.collect do | each |
    each.name
  end.join( "," )

@yasuhito
Copy link

yasuhito commented Mar 6, 2013

Ideally, how the ports directive in trema_switch { ... } and the link directive should look like? I guess there are some options for it:

# ports
ports [ 1, 2, 3 ]  # as an Array
ports 1, 2, 3  # as normal arguments
ports 3  # total number of ports
ports "if_trema1", "if_trema2", "if_trema3"  # internal device name (Linux)


# ...or by extending the link syntax,
link "host1", "lsw:1"  # port number is specified after the ':'
link "host2", "lsw:2"
link "host3", "lsw:3"

I guess the last one is close to what you wanted, and this extension requires not much modifications to the current implementation.

@nickkaranatsios
Copy link
Author

require "docile"

class GroupAction
  attr_reader :group_id
  def initialize group_id
    @group_id = group_id
  end
end

class DecMplsTtl
  def initialize
  end
end

class ActionBuilder
  attr_accessor :actions
  def initialize
    @actions = []
  end
  def group group_id
    ga = GroupAction.new group_id
    @actions << ga
    puts ga.inspect
  end
  def dec_mpls_ttl
    dttl = DecMplsTtl.new
    puts dttl.inspect
    @actions << dttl
  end
end


def actions( &block )
  builder = ActionBuilder.new
  Docile.dsl_eval( builder, &block )
  puts builder.actions.inspect
end


actions do
  group 1
  dec_mpls_ttl
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment