-
Notifications
You must be signed in to change notification settings - Fork 0
/
learning-switch.rb
48 lines (36 loc) · 942 Bytes
/
learning-switch.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require "fdb"
class LearningSwitch < Controller
def start
@fdb = FDB.new
end
def packet_in dpid, message
@fdb.learn message.macsa, message.in_port
port_no = @fdb.lookup( message.macda )
if port_no
flow_mod dpid, message, port_no
packet_out dpid, message, port_no
else
flood dpid, message
end
end
##############################################################################
private
##############################################################################
def flow_mod dpid, message, port_no
send_flow_mod_add(
dpid,
:match => ExactMatch.from( message ),
:actions => ActionOutput.new( port_no )
)
end
def packet_out dpid, message, port_no
send_packet_out(
dpid,
:packet_in => message,
:actions => ActionOutput.new( port_no )
)
end
def flood dpid, message
packet_out dpid, message, OFPP_FLOOD
end
end