Class: Dcmgr::NodeModules::OvsOfctl

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/dcmgr/node_modules/openflow_controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logger

create, default_logdev, included

Constructor Details

#initialize(config) ⇒ OvsOfctl

Returns a new instance of OvsOfctl.



579
580
581
582
583
584
585
586
587
# File 'lib/dcmgr/node_modules/openflow_controller.rb', line 579

def initialize config
  # TODO: Make ovs_vsctl use a real config option.
  @ovs_ofctl = config.ovs_ofctl_path
  @ovs_vsctl = config.ovs_ofctl_path.dup
  @ovs_vsctl[/ovs-ofctl/] = 'ovs-vsctl'

  @switch = config.bridge_novlan
  @verbose = config.verbose_openflow
end

Instance Attribute Details

#ovs_ofctlObject

Returns the value of attribute ovs_ofctl.



576
577
578
# File 'lib/dcmgr/node_modules/openflow_controller.rb', line 576

def ovs_ofctl
  @ovs_ofctl
end

#verboseObject

Returns the value of attribute verbose.



577
578
579
# File 'lib/dcmgr/node_modules/openflow_controller.rb', line 577

def verbose
  @verbose
end

Instance Method Details

#add_flow(flow_match, actions) ⇒ Object



589
590
591
592
# File 'lib/dcmgr/node_modules/openflow_controller.rb', line 589

def add_flow flow_match, actions
  command = "#{@ovs_ofctl} add-flow #{@switch} #{flow_match},actions=#{actions}"
  logger.debug "'#{command}' => #{system(command)}."
end

#add_flows_from_list(flows) ⇒ Object



599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
# File 'lib/dcmgr/node_modules/openflow_controller.rb', line 599

def add_flows_from_list(flows)
  recmds = []

  eos = "__EOS_#{Isono::Util.gen_id}___"
  recmds << "#{@ovs_ofctl} add-flow #{@switch} - <<'#{eos}'"
  flows.each { |flow|
    full_flow = "#{flow[0]},actions=#{flow[1]}"
    puts "ovs-ofctl add-flow #{@switch} #{full_flow}" if verbose == true
    recmds << full_flow
  }
  recmds << "#{eos}"

  logger.debug("applying flow(s): #{recmds.size - 2}")
  system(recmds.join("\n"))
end

#add_gre_tunnel(tunnel_name, remote_ip, key) ⇒ Object



648
649
650
# File 'lib/dcmgr/node_modules/openflow_controller.rb', line 648

def add_gre_tunnel tunnel_name, remote_ip, key
  system("#{@ovs_vsctl} add-port #{@switch} #{tunnel_name} -- set interface #{tunnel_name} type=gre options:remote_ip=#{remote_ip} options:key=#{key}")
end

#arg_in_port(port_number) ⇒ Object



630
631
632
633
634
635
636
637
# File 'lib/dcmgr/node_modules/openflow_controller.rb', line 630

def arg_in_port port_number
  case port_number
  when OpenFlowController::OFPP_LOCAL
    return "in_port=local"
  else
    return "in_port=#{port_number}" if port_number < OpenFlowController::OFPP_MAX
  end
end

#arg_output(port_number) ⇒ Object



639
640
641
642
643
644
645
646
# File 'lib/dcmgr/node_modules/openflow_controller.rb', line 639

def arg_output port_number
  case port_number
  when OpenFlowController::OFPP_LOCAL
    return "local"
  else
    return "output:#{port_number}" if port_number < OpenFlowController::OFPP_MAX
  end
end

#del_flow(flow_match) ⇒ Object



594
595
596
597
# File 'lib/dcmgr/node_modules/openflow_controller.rb', line 594

def del_flow flow_match
  command = "#{@ovs_ofctl} del-flows #{@switch} #{flow_match}"
  logger.debug "'#{command}' => #{system(command)}."
end

#del_flows_from_list(flows) ⇒ Object



615
616
617
618
619
620
621
622
623
624
625
626
627
628
# File 'lib/dcmgr/node_modules/openflow_controller.rb', line 615

def del_flows_from_list(flows)
  recmds = []

  eos = "__EOS_#{Isono::Util.gen_id}___"
  recmds << "#{@ovs_ofctl} del-flows #{@switch} - <<'#{eos}'"
  flows.each { |flow|
    puts "ovs-ofctl del-flows #{@switch} #{flow}" if verbose == true
    recmds << flow
  }
  recmds << "#{eos}"

  logger.debug("removing flow(s): #{recmds.size - 2}")
  system(recmds.join("\n"))
end