Class: OFSwitch

Inherits:
OpenflowNode show all
Defined in:
lib/openflowdev/of_switch.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller: nil, name: nil, dpid: nil) ⇒ OFSwitch

Returns a new instance of OFSwitch.



40
41
42
43
# File 'lib/openflowdev/of_switch.rb', line 40

def initialize(controller: nil, name: nil, dpid: nil)
  super(controller: controller, name: name)
  @dpid = dpid
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



38
39
40
# File 'lib/openflowdev/of_switch.rb', line 38

def name
  @name
end

Instance Method Details

#add_modify_flow(flow) ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
# File 'lib/openflowdev/of_switch.rb', line 148

def add_modify_flow(flow)
  put_uri = "#{@controller.get_node_config_uri(self)}/table/#{flow.table_id}/"\
    "flow/#{flow.id}"
  response = @controller.rest_agent.put_request(put_uri, flow.to_hash,
    headers: {'Content-Type' => 'application/yang.data+json'})
  if response.code.to_i == 200
    NetconfResponse.new(NetconfResponseStatus::OK)
  else
    handle_error_response(response)
  end
end

#delete_flow(table_id: nil, flow_id: nil) ⇒ Object

Raises:

  • (ArgumentError)


171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/openflowdev/of_switch.rb', line 171

def delete_flow(table_id: nil, flow_id: nil)
  raise ArgumentError, "Table ID (table_id) required" unless table_id
  raise ArgumentError, "Flow ID (flow_id) required" unless flow_id
  delete_uri = "#{@controller.get_node_config_uri(self)}/table/#{table_id}/"\
    "flow/#{flow_id}"
  response = @controller.rest_agent.delete_request(delete_uri)
  if response.code.to_i == 200
    NetconfResponse.new(NetconfResponseStatus::OK)
  else
    handle_error_response(response)
  end
end

#get_configured_flow(table_id: nil, flow_id: nil) ⇒ Object

Raises:

  • (ArgumentError)


160
161
162
163
164
165
166
167
168
169
# File 'lib/openflowdev/of_switch.rb', line 160

def get_configured_flow(table_id: nil, flow_id: nil)
  raise ArgumentError, "Table ID (table_id) required" unless table_id
  raise ArgumentError, "Flow ID (flow_id) required" unless flow_id
  get_uri = "#{@controller.get_node_config_uri(self)}/table/#{table_id}/"\
    "flow/#{flow_id}"
  response = @controller.rest_agent.get_request(get_uri)
  check_response_for_success(response) do |body|
    NetconfResponse.new(NetconfResponseStatus::OK, body)
  end
end

#get_configured_flows(table_id: nil) ⇒ Object

Raises:

  • (ArgumentError)


189
190
191
192
# File 'lib/openflowdev/of_switch.rb', line 189

def get_configured_flows(table_id: nil)
  raise ArgumentError, "Table ID (table_id) required" unless table_id
  get_flows(table_id: table_id, is_operational: false)
end

#get_configured_flows_ovs_syntax(table_id: nil, sort: false) ⇒ Object

Raises:

  • (ArgumentError)


209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/openflowdev/of_switch.rb', line 209

def get_configured_flows_ovs_syntax(table_id: nil, sort: false)
  raise ArgumentError, "Table ID (table_id) required" unless table_id
  response = get_configured_flows(table_id: table_id)
  if response.status == NetconfResponseStatus::OK
    flows = []
    response.body.sort! { |x,y| x['priority'] <=> y['priority']} if sort
    response.body.each do |flow|
      flows << odl_to_ovs_flow_syntax(flow)
    end
    NetconfResponse.new(NetconfResponseStatus::OK, flows)
  else
    response
  end
end

#get_features_infoObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/openflowdev/of_switch.rb', line 74

def get_features_info
  get_uri = @controller.get_node_operational_uri(self)
  response = @controller.rest_agent.get_request(get_uri)
  check_response_for_success(response) do |body|
    if body.has_key?('node') && body['node'].is_a?(Array) &&
        body['node'][0].has_key?('flow-node-inventory:switch-features')
      properties = body['node'][0]['flow-node-inventory:switch-features']
      feature_info = {'max_tables' => properties['max_tables'],
        'max_buffers' => properties['max_buffers']}
      capabilities = []
      properties['capabilities'].each do |capability|
        capabilities << capability.gsub('flow-node-inventory:flow-feature-capability-', '')
      end
      feature_info['capabilities'] = capabilities
      NetconfResponse.new(NetconfResponseStatus::OK, feature_info)
    else
      NetconfResponse.new(NetconfResponseStatus::DATA_NOT_FOUND)
    end
  end
end

#get_operational_flows(table_id: nil) ⇒ Object

Raises:

  • (ArgumentError)


184
185
186
187
# File 'lib/openflowdev/of_switch.rb', line 184

def get_operational_flows(table_id: nil)
  raise ArgumentError, "Table ID (table_id) required" unless table_id
  get_flows(table_id: table_id)
end

#get_operational_flows_ovs_syntax(table_id: nil, sort: false) ⇒ Object

Raises:

  • (ArgumentError)


194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/openflowdev/of_switch.rb', line 194

def get_operational_flows_ovs_syntax(table_id: nil, sort: false)
  raise ArgumentError, "Table ID (table_id) required" unless table_id
  response = get_operational_flows(table_id: table_id)
  if response.status == NetconfResponseStatus::OK
    flows = []
    response.body.sort! { |x,y| x['priority'] <=> y['priority']} if sort
    response.body.each do |flow|
      flows << odl_to_ovs_flow_syntax(flow)
    end
    NetconfResponse.new(NetconfResponseStatus::OK, flows)
  else
    response
  end
end

#get_port_detail_info(port) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/openflowdev/of_switch.rb', line 134

def get_port_detail_info(port)
  get_uri = "#{@controller.get_node_operational_uri(self)}/node-connector/"\
    "#{self.name}:#{port}"
  response = @controller.rest_agent.get_request(get_uri)
  check_response_for_success(response) do |body|
    if body.has_key?('node-connector') &&
        body['node-connector'].is_a?(Array) && body['node-connector'][0]
      NetconfResponse.new(NetconfResponseStatus::OK, body['node-connector'][0])
    else
      NetconfResponse.new(NetconfResponseStatus::DATA_NOT_FOUND)
    end
  end
end

#get_ports_brief_infoObject



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/openflowdev/of_switch.rb', line 112

def get_ports_brief_info
  get_uri = @controller.get_node_operational_uri(self)
  response = @controller.rest_agent.get_request(get_uri)
  check_response_for_success(response) do |body|
    if body.has_key?('node') && body['node'].is_a?(Array) &&
        body['node'][0].has_key?('node-connector')
      ports_info = []
      body['node'][0]['node-connector'].each do |port|
        port_info = {'id' => port['id'],
          'number' => port['flow-node-inventory:port-number'],
          'name' => port['flow-node-inventory:name'],
          'mac-address' => port['flow-node-inventory:hardware-address'],
          'current-feature' => port['flow-node-inventory:current-feature'].upcase}
        ports_info << port_info
      end
      NetconfResponse.new(NetconfResponseStatus::OK, ports_info)
    else
      NetconfResponse.new(NetconfResponseStatus::DATA_NOT_FOUND)
    end
  end
end

#get_ports_listObject



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/openflowdev/of_switch.rb', line 95

def get_ports_list
  get_uri = @controller.get_node_operational_uri(self)
  response = @controller.rest_agent.get_request(get_uri)
  check_response_for_success(response) do |body|
    if body.has_key?('node') && body['node'].is_a?(Array) &&
        body['node'][0].has_key?('node-connector')
      ports = []
      body['node'][0]['node-connector'].each do |port|
        ports << port['flow-node-inventory:port-number']
      end
      NetconfResponse.new(NetconfResponseStatus::OK, ports)
    else
      NetconfResponse.new(NetconfResponseStatus::DATA_NOT_FOUND)
    end
  end
end

#get_switch_infoObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/openflowdev/of_switch.rb', line 45

def get_switch_info
  get_uri = @controller.get_node_operational_uri(self)
  response = @controller.rest_agent.get_request(get_uri)
  check_response_for_success(response) do |body|
    general_info = {}
    if body.has_key?('node') && body['node'].is_a?(Array)
      properties = body['node'][0]
      if properties.has_key?('flow-node-inventory:manufacturer')
        general_info['manufacturer'] = properties['flow-node-inventory:manufacturer']
      end
      if properties.has_key?('flow-node-inventory:serial-number')
        general_info['serial-number'] = properties['flow-node-inventory:serial-number']
      end
      if properties.has_key?('flow-node-inventory:software')
        general_info['software'] = properties['flow-node-inventory:software']
      end
      if properties.has_key?('flow-node-inventory:hardware')
        general_info['hardware'] = properties['flow-node-inventory:hardware']
      end
      if properties.has_key?('flow-node-inventory:description')
        general_info['description'] = properties['flow-node-inventory:description']
      end
      NetconfResponse.new(NetconfResponseStatus::OK, general_info)
    else
      NetconfResponse.new(NetconfResponseStatus::DATA_NOT_FOUND)
    end
  end
end