-
Notifications
You must be signed in to change notification settings - Fork 28
/
datapath.rb
59 lines (46 loc) · 1.54 KB
/
datapath.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
49
50
51
52
53
54
55
56
57
58
59
# -*- coding: utf-8 -*-
module Dcmgr
module EdgeNetworking
module OpenFlow
# OpenFlow datapath allows us to send OF messages and ovs-ofctl
# commands to a specific bridge/switch.
class OpenFlowDatapath
attr_reader :controller
attr_reader :datapath_id
attr_reader :ovs_ofctl
def initialize ofc, dp_id, ofctl
@controller = ofc
@datapath_id = dp_id
@ovs_ofctl = ofctl
end
def switch
controller.switches[datapath_id]
end
def add_flow flow
ovs_ofctl.add_flow flow
end
def add_flows flows
ovs_ofctl.add_flows_from_list flows unless flows.empty?
end
def del_flows flows
ovs_ofctl.del_flows_from_list flows unless flows.empty?
end
def send_message message
controller.send_message datapath_id, message
end
def send_packet_out params
controller.send_packet_out datapath_id, params
end
def send_arp out_port, op_code, src_hw, src_ip, dst_hw, dst_ip
controller.send_arp datapath_id, out_port, op_code, src_hw, src_ip, dst_hw, dst_ip
end
def send_icmp out_port, options
controller.send_icmp datapath_id, out_port, options
end
def send_udp out_port, src_hw, src_ip, src_port, dst_hw, dst_ip, dst_port, payload
controller.send_udp datapath_id, out_port, src_hw, src_ip, src_port, dst_hw, dst_ip, dst_port, payload
end
end
end
end
end