Contents

REST API

Background:

  • Given I send and accept JSON
  • And I set the environment variables to:
    variablevalue
    TREMA_LOG_DIR.
    TREMA_PID_DIR.
    TREMA_SOCKET_DIR.
  • And I trema run "./lib/routing_switch.rb" with args "-d -- --slicing"

Scenario: POST /slices

@rest_api

  • When I send a POST request for "/slices" with body "{name: 'foo'}"
  • Then the response should be "201"
  • When I successfully run `slice list`
  • Then the stdout from "slice list" should contain exactly "foo\n"

Scenario: POST /slices x2 (409 Conflict)

@rest_api

  • Given I send a POST request for "/slices" with body "{name: 'foo'}"
  • When I send a POST request for "/slices" with body "{name: 'foo'}"
  • Then the response should be "409"
  • And the JSON response should be:
    json
    {"error": "Slice foo already exists"}

Scenario: DELETE /slices

@rest_api

  • Given I successfully run `slice add foo`
  • When I send a DELETE request for "/slices" with body "{name: 'foo'}"
  • Then the response should be "200"
  • When I successfully run `slice list`
  • Then the stdout from "slice list" should contain exactly ""

Scenario: DELETE /slices (404 slice)

@rest_api

  • When I send a DELETE request for "/slices" with body "{name: 'foo'}"
  • Then the response should be "404"
  • And the JSON response should be:
    json
    {"error": "Slice foo not found"}

Scenario: GET /slices (no slices)

@rest_api

  • When I send a GET request for "/slices"
  • Then the response should be "200"
  • And the JSON response should be "[]"

Scenario: GET /slices (one slice)

@rest_api

  • Given I successfully run `slice add foo`
  • When I send a GET request for "/slices"
  • Then the response should be "200"
  • And the JSON response should be:
    json
    [{"name": "foo"}]

Scenario: GET /slices (three slices)

@rest_api

  • Given I successfully run `slice add foo`
  • And I successfully run `slice add bar`
  • And I successfully run `slice add baz`
  • When I send a GET request for "/slices"
  • Then the response should be "200"
  • And the JSON response should be:
    json
    [{"name": "foo"}, {"name": "bar"}, {"name": "baz"}]

Scenario: GET /slices/:slice_id

@rest_api

  • Given I successfully run `slice add foo`
  • When I send a GET request for "/slices/foo"
  • Then the response should be "200"
  • And the JSON response should be:
    json
    {"name": "foo"}

Scenario: GET /slices/:slice_id (404)

@rest_api

  • Given I send a GET request for "/slices/bar"
  • Then the response should be "404"
  • And the JSON response should be:
    json
    {"error": "Slice bar not found"}

Scenario: POST /slices/:slice_id/ports

@rest_api

  • When I send a POST request for "/slices" with body "{name: 'foo'}"
  • And I send a POST request for "/slices/foo/ports" with body "{dpid: 1, port_no: 1}"
  • Then the response should be "201"
  • When I successfully run `slice list`
  • Then the stdout from "slice list" should contain exactly:
    text
    foo
      0x1:1
    

Scenario: POST /slices/:slice_id/ports (404 :slice_id)

@rest_api

  • When I send a POST request for "/slices/foo/ports" with body "{dpid: 1, port_no: 1}"
  • Then the response should be "404"
  • And the JSON response should be:
    json
    {"error": "Slice foo not found"}

Scenario: POST /slices/:slice_id/ports x2 (409 Conflict)

@rest_api

  • Given I send a POST request for "/slices" with body "{name: 'foo'}"
  • And I send a POST request for "/slices/foo/ports" with body "{dpid: 1, port_no: 1}"
  • When I send a POST request for "/slices/foo/ports" with body "{dpid: 1, port_no: 1}"
  • Then the response should be "409"
  • And the JSON response should be:
    json
    {"error": "Port 0x1:1 already exists"}

Scenario: DELETE /slices/:slice_id/ports

@rest_api

  • Given I successfully run `slice add foo`
  • And I successfully run `slice add_port --port 0x1:1 --slice foo`
  • When I send a DELETE request for "/slices/foo/ports" with body "{dpid: 1, port_no: 1}"
  • Then the response should be "200"
  • When I successfully run `slice list`
  • Then the stdout from "slice list" should contain exactly "foo\n"

Scenario: DELETE /slices/:slice_id/ports (404 :slice_id)

@rest_api

  • When I send a DELETE request for "/slices/foo/ports" with body "{dpid: 1, port_no: 1}"
  • Then the response should be "404"
  • And the JSON response should be:
    json
    {"error": "Slice foo not found"}

Scenario: DELETE /slices/:slice_id/ports (404 port)

@rest_api

  • Given I successfully run `slice add foo`
  • And I successfully run `slice add_port --port 0x1:1 --slice foo`
  • When I send a DELETE request for "/slices/foo/ports" with body "{dpid: 2, port_no: 2}"
  • Then the response should be "404"
  • And the JSON response should be:
    json
    {"error": "Port 0x2:2 not found"}

Scenario: GET /slices/:slice_id/ports (no ports)

@rest_api

  • Given I successfully run `slice add foo`
  • When I send a GET request for "/slices/foo/ports"
  • Then the response should be "200"
  • And the JSON response should be "[]"

Scenario: GET /slices/:slice_id/ports (one port)

@rest_api

  • Given I successfully run `slice add foo`
  • And I successfully run `slice add_host --mac 11:11:11:11:11:11 --port 0x1:1 --slice foo`
  • When I send a GET request for "/slices/foo/ports"
  • Then the response should be "200"
  • And the JSON response should be:
    json
    [{"name": "0x1:1", "dpid": 1, "port_no": 1}]

Scenario: GET /slices/:slice_id/ports (three ports)

@rest_api

  • Given I successfully run `slice add foo`
  • And I successfully run `slice add_host --mac 11:11:11:11:11:11 --port 0x1:1 --slice foo`
  • And I successfully run `slice add_host --mac 22:22:22:22:22:22 --port 0x2:1 --slice foo`
  • And I successfully run `slice add_host --mac 33:33:33:33:33:33 --port 0x3:1 --slice foo`
  • When I send a GET request for "/slices/foo/ports"
  • Then the response should be "200"
  • And the JSON response should be:
    json
    [{"name": "0x1:1", "dpid": 1, "port_no": 1}, {"name": "0x2:1", "dpid": 2, "port_no": 1}, {"name": "0x3:1", "dpid": 3, "port_no": 1}]

Scenario: GET /slices/:slice_id/ports (404 :slice_id)

@rest_api

  • When I send a GET request for "/slices/bar/ports"
  • Then the response should be "404"
  • And the JSON response should be:
    json
    {"error": "Slice bar not found"}

Scenario: GET /slices/:slice_id/ports/:port_id

@rest_api

  • Given I successfully run `slice add foo`
  • And I successfully run `slice add_host --mac 11:11:11:11:11:11 --port 0x1:1 --slice foo`
  • When I send a GET request for "/slices/foo/ports/0x1:1"
  • Then the response should be "200"
  • And the JSON response should be:
    json
    {"name": "0x1:1", "dpid": 1, "port_no": 1}

Scenario: GET /slices/:slice_id/ports/:port_id (404 :slice_id)

@rest_api

  • When I send a GET request for "/slices/bar/ports/0x1:1"
  • Then the response should be "404"
  • And the JSON response should be:
    json
    {"error": "Slice bar not found"}

Scenario: GET /slices/:slice_id/ports/:port_id (404 :port_id)

@rest_api

  • Given I successfully run `slice add foo`
  • When I send a GET request for "/slices/foo/ports/0x1:1"
  • Then the response should be "404"
  • And the JSON response should be:
    json
    {"error": "Port 0x1:1 not found"}

Scenario: POST /slices/:slice_id/ports/:port_id/mac_addresses

@rest_api

  • When I send a POST request for "/slices" with body "{name: 'foo'}"
  • And I send a POST request for "/slices/foo/ports/0x1:1/mac_addresses" with body "{name: '11:11:11:11:11:11'}"
  • Then the response should be "201"
  • When I successfully run `slice list`
  • Then the stdout from "slice list" should contain exactly:
    text
    foo
      0x1:1
        11:11:11:11:11:11
    

Scenario: POST /slices/:slice_id/ports/:port_id/mac_addresses (404 :slice_id)

@rest_api

  • When I send a POST request for "/slices/foo/ports/0x1:1/mac_addresses" with body "{name: '11:11:11:11:11:11'}"
  • Then the response should be "404"
  • And the JSON response should be:
    json
    {"error": "Slice foo not found"}

Scenario: POST /slices/:slice_id/ports/:port_id/mac_addresses x2 (409 Conflict)

@rest_api

  • Given I send a POST request for "/slices" with body "{name: 'foo'}"
  • And I send a POST request for "/slices/foo/ports/0x1:1/mac_addresses" with body "{name: '11:11:11:11:11:11'}"
  • When I send a POST request for "/slices/foo/ports/0x1:1/mac_addresses" with body "{name: '11:11:11:11:11:11'}"
  • Then the response should be "409"
  • And the JSON response should be:
    json
    {"error": "MAC address 11:11:11:11:11:11 already exists"}

Scenario: DELETE /slices/:slice_id/ports/:port_id/mac_addresses

@rest_api

  • Given I successfully run `slice add foo`
  • And I successfully run `slice add_host --mac 11:11:11:11:11:11 --port 0x1:1 --slice foo`
  • When I send a DELETE request for "/slices/foo/ports/0x1:1/mac_addresses" with body "{name: '11:11:11:11:11:11'}"
  • Then the response should be "200"
  • When I successfully run `slice list`
  • Then the stdout from "slice list" should contain exactly:
    text
    foo
      0x1:1
    

Scenario: DELETE /slices/:slice_id/ports/:port_id/mac_addresses (404 :port_id)

@rest_api

  • Given I successfully run `slice add foo`
  • When I send a DELETE request for "/slices/foo/ports/0x1:1/mac_addresses" with body "{name: '11:11:11:11:11:11'}"
  • Then the response should be "404"
  • And the JSON response should be:
    json
    {"error": "Port 0x1:1 not found"}

Scenario: DELETE /slices/:slice_id/ports/:port_id/mac_addresses (404 mac_address)

@rest_api

  • Given I successfully run `slice add foo`
  • And I successfully run `slice add_port --port 0x1:1 --slice foo`
  • When I send a DELETE request for "/slices/foo/ports/0x1:1/mac_addresses" with body "{name: '11:11:11:11:11:11'}"
  • Then the response should be "404"
  • And the JSON response should be:
    json
    {"error": "MAC address 11:11:11:11:11:11 not found"}

Scenario: GET /slices/:slice_id/ports/:port_id/mac_addresses (one MAC address)

@rest_api

  • Given I successfully run `slice add foo`
  • And I successfully run `slice add_host --mac 11:11:11:11:11:11 --port 0x1:1 --slice foo`
  • When I send a GET request for "/slices/foo/ports/0x1:1/mac_addresses"
  • Then the response should be "200"
  • And the JSON response should be:
    json
    [{"name": "11:11:11:11:11:11"}]

Scenario: GET /slices/:slice_id/ports/:port_id/mac_addresses (three MAC addresses)

@rest_api

  • Given I successfully run `slice add foo`
  • And I successfully run `slice add_host --mac 11:11:11:11:11:11 --port 0x1:1 --slice foo`
  • And I successfully run `slice add_host --mac 22:22:22:22:22:22 --port 0x1:1 --slice foo`
  • And I successfully run `slice add_host --mac 33:33:33:33:33:33 --port 0x1:1 --slice foo`
  • When I send a GET request for "/slices/foo/ports/0x1:1/mac_addresses"
  • Then the response should be "200"
  • And the JSON response should be:
    json
    [{"name": "11:11:11:11:11:11"}, {"name": "22:22:22:22:22:22"}, {"name": "33:33:33:33:33:33"}]

Scenario: GET /slices/:slice_id/ports/:port_id/mac_addresses (:slice_id 404)

@rest_api

  • When I send a GET request for "/slices/bar/ports/0x1:1/mac_addresses"
  • Then the response should be "404"
  • And the JSON response should be:
    json
    {"error": "Slice bar not found"}

Scenario: GET /slices/:slice_id/ports/:port_id/mac_addresses (:port_id 404)

@rest_api

  • Given I successfully run `slice add foo`
  • When I send a GET request for "/slices/foo/ports/0x1:1/mac_addresses"
  • Then the response should be "404"
  • And the JSON response should be:
    json
    {"error": "Port 0x1:1 not found"}

Scenario: GET /slices/:slice_id/ports/:port_id/mac_addresses/:mac_address_id

@rest_api

  • Given I successfully run `slice add foo`
  • And I successfully run `slice add_host --mac 11:11:11:11:11:11 --port 0x1:1 --slice foo`
  • When I send a GET request for "/slices/foo/ports/0x1:1/mac_addresses/11:11:11:11:11:11"
  • Then the response should be "200"
  • And the JSON response should be:
    json
    {"name": "11:11:11:11:11:11"}

Scenario: GET /slices/:slice_id/ports/:port_id/mac_addresses/:mac_address_id (:slice_id 404)

@rest_api

  • When I send a GET request for "/slices/bar/ports/0x1:1/mac_addresses/11:11:11:11:11:11"
  • Then the response should be "404"
  • And the JSON response should be:
    json
    {"error": "Slice bar not found"}

Scenario: GET /slices/:slice_id/ports/:port_id/mac_addresses/:mac_address_id (:port_id 404)

@rest_api

  • Given I successfully run `slice add foo`
  • When I send a GET request for "/slices/foo/ports/0x1:1/mac_addresses/11:11:11:11:11:11"
  • Then the response should be "404"
  • And the JSON response should be:
    json
    {"error": "Port 0x1:1 not found"}

Scenario: GET /slices/:slice_id/ports/:port_id/mac_addresses/:mac_address_id (:mac_address_id 404)

@rest_api

  • Given I successfully run `slice add foo`
  • And I successfully run `slice add_host --mac 11:11:11:11:11:11 --port 0x1:1 --slice foo`
  • When I send a GET request for "/slices/foo/ports/0x1:1/mac_addresses/22:22:22:22:22:22"
  • Then the response should be "404"
  • And the JSON response should be:
    json
    {"error": "MAC address 22:22:22:22:22:22 not found"}

Source: features/rest_api.feature at commit e5a54006, Routing Switch (GPL license).