Skip to content

Commit

Permalink
Delete Open vSwitch flows matching the nic port
Browse files Browse the repository at this point in the history
When two users instantiate a VM template, they both get the same IP, so
the same MAC address, in their own respective networks differenciated by
VLAN ID.

When one of them delete her VM, the flow is removed for the other VM too
since the flows are selected only by matching MAC address.

* src/vnm_mad/remotes/ovswitch/OpenvSwitch.rb (OpenvSwitchVLAN#deactivate):
  Delet flows on the nic port matching the MAC address, take care of
  nonexistent port.

* src/vnm_mad/remotes/ovswitch/OpenvSwitch.rb (OpenvSwitchVLAN#del_flows):
  Remove useless function.
  • Loading branch information
baby-gnu committed Dec 1, 2015
1 parent f1c922e commit b847c78
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions src/vnm_mad/remotes/ovswitch/OpenvSwitch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ def deactivate
process do |nic|
@nic = nic

# Remove flows
del_flows
# Remove flows on the nic port if it exists
in_port = port
del_flow "in_port=#{in_port},dl_src=#{@nic[:mac]}" if not in_port.nil?
end

unlock
Expand Down Expand Up @@ -156,22 +157,6 @@ def configure_fw
end
end

def del_flows
in_port = ""

dump_flows = "#{command(:ovs_ofctl)} dump-flows #{@nic[:bridge]}"
`#{dump_flows}`.lines do |flow|
next unless flow.match("#{@nic[:mac]}")
flow = flow.split.select{|e| e.match(@nic[:mac])}.first
if in_port.empty? and (m = flow.match(/in_port=(\d+)/))
in_port = m[1]
end
del_flow flow
end

del_flow "in_port=#{in_port}" if !in_port.empty?
end

def add_flow(filter,action,priority=nil)
priority = (priority.to_s.empty? ? "" : "priority=#{priority},")

Expand All @@ -195,6 +180,9 @@ def port
dump_ports = `#{command(:ovs_ofctl)} \
dump-ports #{@nic[:bridge]} #{@nic[:tap]}`

# Do not return 1 if no port is associated with the interface
return nil if dump_ports.empty?

@nic[:port] = dump_ports.scan(/^\s*port\s*(\d+):/).flatten.first
end

Expand Down

0 comments on commit b847c78

Please sign in to comment.