class Controller

Class that represents a Controller device.

Attributes

ip[R]

String : IP address of the BVC. e.g. 192.168.56.101

password[R]

String : Admin password for logon to BVC RESTCONF API. e.g. admin

port[R]

String : Port number of the BVC RESTCONF API. e.g. 8181

rest_agent[R]

RestAgent : The REST agent connected to controller.

timeout[R]

Integer : Number of seconds to wait for a response from BVC to RESTCONF request. e.g. 5

username[R]

String : Admin userid for logon to BVC RESTCONF API. e.g. admin

Public Class Methods

new(ip_addr: nil, port_number: 8181, admin_name: nil, admin_password: nil, timeout_in_s: 5) click to toggle source

Parameters

  • ip_addr

    String : IP address of the BVC. e.g. 192.168.56.101

  • port_number

    String : Port number of the BVC RESTCONF API. e.g. 8181

  • admin_name

    String : Admin userid for logon to BVC RESTCONF API. e.g. admin

  • admin_password

    String : Admin password for logon to BVC RESTCONF API. e.g. admin

  • timeout_in_s

    Integer : Number of seconds to wait for a response from BVC to RESTCONF request. e.g. 5

# File lib/controller/controller.rb, line 62
def initialize(ip_addr: nil, port_number: 8181, admin_name: nil,
    admin_password: nil, timeout_in_s: 5) 
  raise ArgumentError, "IP Address (ip_addr) required" unless ip_addr
  raise ArgumentError, "Admin Username (admin_name) required" unless admin_name
  raise ArgumentError, "Admin Password (admin_password) required" unless admin_password
  @ip = ip_addr
  @port = port_number
  @username = admin_name
  @password = admin_password
  @timeout = timeout_in_s
  
  @rest_agent = RestAgent.new("http://#{@ip}:#{@port}", username: @username,
    password: @password, open_timeout: @timeout)
end

Public Instance Methods

add_netconf_node(node) click to toggle source

Connect a netconf device to the controller (for example connect vrouter to controller via NetConf)

Parameters

Return Value

# File lib/controller/controller.rb, line 498
def add_netconf_node(node)
  post_uri = "/restconf/config/opendaylight-inventory:nodes/node/"       "controller-config/yang-ext:mount/config:modules"
  post_body = generate_node_xml(node)    
  response = @rest_agent.post_request(post_uri, post_body,
    headers: {'Content-Type' => "application/xml",
      'Accept' => "application/xml"})
  check_response_for_success(response) do
      NetconfResponse.new(NetconfResponseStatus::OK)
  end
end
check_node_config_status(node_name) click to toggle source

Return the configuration status of the node.

Parameters

Return Value

# File lib/controller/controller.rb, line 416
def check_node_config_status(node_name)
  get_uri = "/restconf/config/opendaylight-inventory:nodes/node/#{node_name}"
  response = @rest_agent.get_request(get_uri)
  check_response_for_success(response) do
    NetconfResponse.new(NetconfResponseStatus::NODE_CONFIGURED,
      JSON.parse(response.body))
  end
end
check_node_conn_status(node_name) click to toggle source

Return the connection status of the node to the controller.

Parameters

Return Value

# File lib/controller/controller.rb, line 433
def check_node_conn_status(node_name)
  get_uri = "/restconf/operational/opendaylight-inventory:nodes/node/"       "#{node_name}"
  response = @rest_agent.get_request(get_uri)
  if response.code.to_i == 404
    NetconfResponse.new(NetconfResponseStatus::NODE_NOT_FOUND)
  else
    check_response_for_success(response) do |body|
      connected = false
      if body.has_key?('node') && body['node'][0] && body['node'][0].has_key?('id')
        if body['node'][0].has_key?('netconf-node-inventory:connected')
          if body['node'][0]['netconf-node-inventory:connected']
            connected = true
          end
        end
      end
      if connected
        NetconfResponse.new(NetconfResponseStatus::NODE_CONNECTED)
      else
        NetconfResponse.new(NetconfResponseStatus::NODE_DISCONNECTED)
      end
    end
  end
end
delete_netconf_node(node) click to toggle source

Disconnect a netconf device from the controller.

Parameters

  • node

    NetconfNode : node to disconnect from the controller.

Return Value

# File lib/controller/controller.rb, line 518
def delete_netconf_node(node)
  delete_uri = "/restconf/config/opendaylight-inventory:nodes/node/"       "controller-config/yang-ext:mount/config:modules/module/"       "odl-sal-netconf-connector-cfg:sal-netconf-connector/#{node.name}"
  response = @rest_agent.delete_request(delete_uri)
  # need to do the check here because there is no response body and the code
  # is a 200 instead of 204
  if response.code.to_i == 200
    NetconfResponse.new(NetconfResponseStatus::OK)
  else
    handle_error_response(response)
  end
end
get_all_modules_operational_state() click to toggle source

Return a list of modules and their operational state.

Return Value

# File lib/controller/controller.rb, line 194
def get_all_modules_operational_state
  get_uri = "/restconf/operational/opendaylight-inventory:nodes/node/"       "controller-config/yang-ext:mount/config:modules"
  response = @rest_agent.get_request(get_uri)
  response.body.gsub!("\\\n", "")
  check_response_for_success(response) do |body|
    if body.has_key?('modules') && body['modules'].has_key?('module')
      NetconfResponse.new(NetconfResponseStatus::OK, body['modules']['module'])
    else
      NetconfResponse.new(NetconfResponseStatus::DATA_NOT_FOUND)
    end
  end
end
get_all_nodes_conn_status() click to toggle source

Return a list of nodes and the status of their connection to the controller.

Return Value

# File lib/controller/controller.rb, line 464
def get_all_nodes_conn_status
  get_uri = "/restconf/operational/opendaylight-inventory:nodes"
  response = @rest_agent.get_request(get_uri)
  check_response_for_success(response) do |body|
    if body.has_key?('nodes') && body['nodes'].has_key?('node')
      conn_list = []
      body['nodes']['node'].each do |node|
        is_connected = false
        if node['id'].include?('openflow')
          # OpenFlow devices connect to controller (unlike NETCONF nodes),
          # so if we see one, then it is 'connected'
          is_connected = true
        elsif node.has_key?('netconf-node-inventory:connected')
          is_connected = node['netconf-node-inventory:connected']
        end
        conn_status = {:node => node['id'],
          :connected => is_connected}
        conn_list << conn_status
      end
      NetconfResponse.new(NetconfResponseStatus::OK, conn_list)
    else
      NetconfResponse.new(NetconfResponseStatus::DATA_NOT_FOUND)
    end
  end
end
get_all_nodes_in_config() click to toggle source

Return a list of nodes in the controller's config data store

Return Value

# File lib/controller/controller.rb, line 279
def get_all_nodes_in_config
  get_uri = "/restconf/config/opendaylight-inventory:nodes"
  response = @rest_agent.get_request(get_uri)
  check_response_for_success(response) do |body|
    if body.has_key?('nodes') && body['nodes'].has_key?('node')
      devices = []
      body['nodes']['node'].each do |node|
        devices << node['id']
      end
      NetconfResponse.new(NetconfResponseStatus::OK, devices)
    else
      NetconfResponse.new(NetconfResponseStatus::DATA_NOT_FOUND)
    end
  end
end
get_ext_mount_config_uri(node) click to toggle source

Return the netconf mountpoint url to the configured node.

Parameters

Return Value

  • String: Url

# File lib/controller/controller.rb, line 570
def get_ext_mount_config_uri(node)
  raise ArgumentError, "Node (node) must be a 'Node' object or a 'Node' "       "subclass object" unless node.is_a?(Node)
  "/restconf/config/opendaylight-inventory:nodes/node/#{node.name}/yang-ext:mount"
end
get_module_operational_state(type: nil, name: nil) click to toggle source

Return operational state for specified module.

Parameters

  • type

    String : module type

  • name

    String : module name

Return Value

# File lib/controller/controller.rb, line 217
def get_module_operational_state(type: nil, name: nil)
  raise ArgumentError, "Type (type) required" unless type
  raise ArgumentError, "Name (name) required" unless name
  get_uri = "/restconf/operational/opendaylight-inventory:nodes/node/"       "controller-config/yang-ext:mount/config:modules/module/"       "#{type}/#{name}"
  response = @rest_agent.get_request(get_uri)
  check_response_for_success(response) do |body|
    if body.has_key?('module')
      NetconfResponse.new(NetconfResponseStatus::OK, body["module"])
    else
      NetconfResponse.new(NetconfResponseStatus::DATA_NOT_FOUND)
    end
  end
end
get_netconf_nodes_conn_status() click to toggle source

Return a list of NETCONF nodes in the operational data store of controller and the status of their connection to the controller.

Return Value

# File lib/controller/controller.rb, line 323
def get_netconf_nodes_conn_status
  get_uri = "/restconf/operational/opendaylight-inventory:nodes"
  response = @rest_agent.get_request(get_uri)
  check_response_for_success(response) do |body|
    if body.has_key?('nodes') && body['nodes'].has_key?('node')
      conn_list = []
      body['nodes']['node'].each do |node|
        unless node['id'].include?('openflow')
          conn_status = {:node => node['id'],
            :connected => node['netconf-node-inventory:connected']}
          conn_list << conn_status
        end
      end
      NetconfResponse.new(NetconfResponseStatus::OK, conn_list)
    else
      NetconfResponse.new(NetconfResponseStatus::DATA_NOT_FOUND)
    end
  end
end
get_netconf_nodes_in_config() click to toggle source

Return a list of NETCONF nodes in the controller's configuration data store

Return Value

# File lib/controller/controller.rb, line 301
def get_netconf_nodes_in_config 
  get_uri = "/restconf/config/opendaylight-inventory:nodes"
  response = @rest_agent.get_request(get_uri)
  check_response_for_success(response) do |body|
    if body.has_key?('nodes') && body['nodes'].has_key?('node')
      devices = []
      body['nodes']['node'].each do |node|
        devices << node['id'] unless node['id'].include?('openflow')
      end
      NetconfResponse.new(NetconfResponseStatus::OK, devices)
    else
      NetconfResponse.new(NetconfResponseStatus::DATA_NOT_FOUND)
    end
  end
end
get_netconf_operations(node_name) click to toggle source

Return a list of operations supported by the indicated node.

Parameters

Return Value

# File lib/controller/controller.rb, line 175
def get_netconf_operations(node_name)
  get_uri = "/restconf/operations/opendaylight-inventory:nodes/node/"       "#{node_name}/yang-ext:mount"
  response = @rest_agent.get_request(get_uri)
  check_response_for_success(response) do |body|
    if body.has_key?('operations')
      NetconfResponse.new(NetconfResponseStatus::OK, body['operations'])
    else
      NetconfResponse.new(NetconfResponseStatus::DATA_NOT_FOUND)
    end
  end
end
get_node_config_uri(node) click to toggle source

Return the url to the configured node.

Parameters

Return Value

  • String: Url

# File lib/controller/controller.rb, line 555
def get_node_config_uri(node)
  raise ArgumentError, "Node (node) must be a 'Node' object or a 'Node' "       "subclass object" unless node.is_a?(Node) ||
    (node.methods.include?(:ancestors) && node.ancestors.include?(Node))
  "/restconf/config/opendaylight-inventory:nodes/node/#{node.name}"
end
get_node_info(node_name) click to toggle source

Return information about a node in the operational data store.

Parameters

Return Value

# File lib/controller/controller.rb, line 395
def get_node_info(node_name)
  get_uri = "/restconf/operational/opendaylight-inventory:nodes/node/"       "#{node_name}"
  response = @rest_agent.get_request(get_uri)
  check_response_for_success(response) do |body|
    if body.has_key?('node')
      NetconfResponse.new(NetconfResponseStatus::OK, body['node'])
    else
      NetconfResponse.new(NetconfResponseStatus::DATA_NOT_FOUND)
    end
  end
end
get_node_operational_uri(node) click to toggle source

Return the url to the operational node.

Parameters

Return Value

  • String: Url

# File lib/controller/controller.rb, line 540
def get_node_operational_uri(node)
  raise ArgumentError, "Node (node) must be a 'Node' object or a 'Node' "       "subclass object" unless node.is_a?(Node) ||
    (node.methods.include?(:ancestors) && node.ancestors.include?(Node))
  "/restconf/operational/opendaylight-inventory:nodes/node/#{node.name}"
end
get_nodes_operational_list() click to toggle source

Return a list of nodes in the controllers operational data store.

Return Value

# File lib/controller/controller.rb, line 349
def get_nodes_operational_list
  get_uri = "/restconf/operational/opendaylight-inventory:nodes"
  response = @rest_agent.get_request(get_uri)
  check_response_for_success(response) do |body|
    if body.has_key?('nodes') && body['nodes'].has_key?('node')
      list = []
      body['nodes']['node'].each do |node|
        list << node['id'] if node['id']
      end
      NetconfResponse.new(NetconfResponseStatus::OK, list)
    else
      NetconfResponse.new(NetconfResponseStatus::DATA_NOT_FOUND)
    end
  end
end
get_openflow_nodes_operational_list() click to toggle source

Return a list of nodes that support OpenFlow in the Controller's operational data store.

Return Value

# File lib/controller/controller.rb, line 371
def get_openflow_nodes_operational_list
  get_uri = "/restconf/operational/opendaylight-inventory:nodes"
  response = @rest_agent.get_request(get_uri)
  check_response_for_success(response) do |body|
    if body.has_key?('nodes') && body['nodes'].has_key?('node')
      filtered_list = []
      body['nodes']['node'].each do |node|
        filtered_list << node['id'] if node['id'].start_with?('openflow')
      end
      NetconfResponse.new(NetconfResponseStatus::OK, filtered_list)
    else
      NetconfResponse.new(NetconfResponseStatus::DATA_NOT_FOUND)
    end
  end
end
get_schema(node_name, id: nil, version: nil) click to toggle source

Return a YANG schema for the indicated schema on the indicated node.

Parameters

  • node_name

    String : name of the node from the get_all_nodes_in_config

  • id

    String : Identifier for schema

  • version

    String : Version/date for schema

Return Value

# File lib/controller/controller.rb, line 108
def get_schema(node_name, id: nil, version: nil)
  raise ArgumentError, "Identifier (id) required" unless id
  raise ArgumentError, "Version (version) required" unless version
  post_uri = "/restconf/operations/opendaylight-inventory:nodes/node/"       "#{node_name}/yang-ext:mount/ietf-netconf-monitoring:get-schema"
  post_body = {:input => {:identifier => id, :version => version,
      :format => 'yang'}}
  response = @rest_agent.post_request(post_uri, post_body)
  check_response_for_success(response) do |body|
    if body.has_key?('get-schema') && body['get-schema'].has_key?('output') &&
        body['get-schema']['output'].has_key?('data')
      NetconfResponse.new(NetconfResponseStatus::OK,
        body['get-schema']['output']['data'])
    else
      NetconfResponse.new(NetconfResponseStatus::DATA_NOT_FOUND)
    end
  end
end
get_schemas(node_name) click to toggle source

Return a list of YANG schemas for the node.

Parameters

Return Value

# File lib/controller/controller.rb, line 85
def get_schemas(node_name)
  get_uri = "/restconf/operational/opendaylight-inventory:nodes/node/"       "#{node_name}/yang-ext:mount/ietf-netconf-monitoring:netconf-state/schemas"
  response = @rest_agent.get_request(get_uri)
  check_response_for_success(response) do |body|
    if body.has_key?('schemas') && body['schemas'].has_key?('schema')
      NetconfResponse.new(NetconfResponseStatus::OK, body['schemas']['schema'])
    else
      NetconfResponse.new(NetconfResponseStatus::DATA_NOT_FOUND)
    end
  end
end
get_service_provider_info(provider_name) click to toggle source

Return info about a single service provider.

Parameters

Return Value

# File lib/controller/controller.rb, line 154
def get_service_provider_info(provider_name)
  get_uri = "/restconf/config/opendaylight-inventory:nodes/node/"       "controller-config/yang-ext:mount/config:services/service/#{provider_name}"
  response = @rest_agent.get_request(get_uri)
  check_response_for_success(response) do |body|
    if body.has_key?('service')
      NetconfResponse.new(NetconfResponseStatus::OK, body['service'])
    else
      NetconfResponse.new(NetconfResponseStatus::DATA_NOT_FOUND)
    end
  end
end
get_service_providers_info() click to toggle source

Return a list of service providers available.

Return Value

# File lib/controller/controller.rb, line 133
def get_service_providers_info
  get_uri = "/restconf/config/opendaylight-inventory:nodes/node/"       "controller-config/yang-ext:mount/config:services"
  response = @rest_agent.get_request(get_uri)
  check_response_for_success(response) do |body|
    if body.has_key?('services') && body['services'].has_key?('service')
      NetconfResponse.new(NetconfResponseStatus::OK, body['services']['service'])
    else
      NetconfResponse.new(NetconfResponseStatus::DATA_NOT_FOUND)
    end
  end
end
get_sessions_info(node_name) click to toggle source

Return sessions for indicated node.

Parameters

Return Value

# File lib/controller/controller.rb, line 241
def get_sessions_info(node_name)
  get_uri = "/restconf/operational/opendaylight-inventory:nodes/node/"       "#{node_name}/yang-ext:mount/ietf-netconf-monitoring:netconf-state/"       "sessions"
  response = @rest_agent.get_request(get_uri)
  check_response_for_success(response) do |body|
    if body.has_key?('sessions')
      NetconfResponse.new(NetconfResponseStatus::OK, body["sessions"])
    else
      NetconfResponse.new(NetconfResponseStatus::DATA_NOT_FOUND)
    end
  end
end
get_streams_info() click to toggle source

Return streams available for subscription.

Return Value

# File lib/controller/controller.rb, line 261
def get_streams_info
  get_uri = "restconf/streams"
  response = @rest_agent.get_request(get_uri)
  check_response_for_success(response) do |body|
    if body.has_key?('streams')
      NetconfResponse.new(NetconfResponseStatus::OK, body['streams'])
    else
      NetconfResponse.new(NetconfResponseStatus::DATA_NOT_FOUND)
    end
  end
end