Skip to content
This repository has been archived by the owner on Jul 31, 2022. It is now read-only.

Commit

Permalink
modify: mac address processing for PBR-LB Reply packets
Browse files Browse the repository at this point in the history
  • Loading branch information
stereocat committed Feb 17, 2013
1 parent 73a285f commit c7cd993
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pbrlbswitch/pbrlb-table.rb
Expand Up @@ -49,6 +49,10 @@ def balance_rserver(tcp_src_port)
end


def dsr?
@dsr
end

def dump
puts "[PbrLbTable::dump]"

Expand Down
41 changes: 40 additions & 1 deletion pbrlbswitch/pbrlbswitch.rb
Expand Up @@ -111,8 +111,10 @@ def handle_arp_request(dpid, message)

port = message.in_port
daddr = message.arp_tpa
interface = @interfaces.find_by_ipaddr(daddr)

@arp_table.update port, message.arp_spa, message.arp_sha

interface = @interfaces.find_by_ipaddr(daddr)
if interface
info "handle_arp_request: port:#{ port }, daddr:#{ daddr }, interface:#{ interface.segment }"
arp_reply = create_arp_reply_from message, interface.hwaddr
Expand All @@ -134,6 +136,8 @@ def handle_ipv4(dpid, message)

if should_pbrlb?(message)
handle_pbrlb_request dpid, message
elsif pbrlb_reply?(message)
handle_pbrlb_reply dpid, message
elsif should_forward?(message)
forward dpid, message
elsif message.icmpv4_echo_request?
Expand Down Expand Up @@ -186,6 +190,41 @@ def handle_pbrlb_request(dpid, message)
end


def pbrlb_reply?(message)
info "[PbrLbSwitch::pbrlb_reply?]"
## now this method can handle only DSR PBRLB

vsvr = @lb_table.vserver
if message.ipv4_saddr.to_a == vsvr.ipaddr.to_a &&
message.tcp? &&
message.tcp_src_port == vsvr.tcp_port
return true
end
end


def handle_pbrlb_reply(dpid, message)
info "[PbrLbSwitch::handle_pbrlb_reply]"

arp_entry = @arp_table.lookup_by_ipaddr(message.ipv4_daddr)
if arp_entry
src_interface = @interfaces.find_by_ipaddr(message.ipv4_saddr)
actions = [
SetEthSrcAddr.new(src_interface.hwaddr.to_s),
SetEthDstAddr.new(arp_entry.hwaddr.to_s),
SendOutPort.new(arp_entry.port)
]
flow_mod dpid, message, actions
packet_out dpid, message.data, actions
else
# when load-balanced reply comes, it already resolved hwaddr of
# client/server each other.
warn "handle_pbrlb_reply: Not found #{message.ipv4_daddr} entry in arp table, to PBRLB REPLY"
@arp_table.dump
end
end


def should_forward?(message)
info "[PbrLbSwitch::should_forward?]"
not @interfaces.find_by_ipaddr(message.ipv4_daddr)
Expand Down

0 comments on commit c7cd993

Please sign in to comment.