Tabelas de Roteamento

Esta é uma API de gerenciamento de tabelas de roteamento de uma conexão de rede. No Linux as tabelas de roteamento representam um conjuto de regras de roteamento que podem ser ativadas por meio de marcações nos pacotes que passam pelo firewall.

Listar tabelas de roteamento

API de listagem de tabelas de roteamento

GET /api/sdwan/routing/tables

Exemplo de requisição

GET /api/sdwan/routing/tables HTTP/1.1
Host: api.exemplo.com
Accept: application/json
Authorization: Bearer <Access-Token>
response = sdk.sdwan.get_routing_tables()
print(response.payload)
const response = sdk.sdwan.getRoutingTables();
console.log(response.payload);

Exemplo de resposta

HTTP/1.1 200 OK
Content-Type: application/json

{
  "routing_tables": [
    {
      "id": 1,
      "name": "routing_table01",
      "enabled": true,
      "table_id": 2,
      "connection_id": "iface:1",
      "interface": "eth0",
      "gateway": "192.168.10.1",
      "routes": [
        {
          "type": "include",
          "addr": "192.127.2.10",
          "nexthop": "192.127.2.200"
        },
        {
          "type": "exclude",
          "addr": "192.122.50.0/24",
          "nexthop": "192.122.50.200",
        }
      ],
      "rules": [
        {
          "type": "from",
          "addr": "192.168.0.0/24"
        },
        {
          "type": "to",
          "addr": "192.172.50.20"
        }
      ],
      "created_at": "2018-12-13T12:20:02.932000+00:00",
      "updated_at": "2018-12-13T12:20:02.932000+00:00"
    },
    {
      "id": 2,
      "name": "routing_table02",
      "enabled": true,
      "table_id": 3,
      "connection_id": "iface:2",
      "interface": "eth1",
      "gateway": "192.168.5.1",
      "routes": [],
      "rules": [],
      "created_at": "2018-12-13T14:15:02.932000+00:00",
      "updated_at": "2018-12-13T14:15:02.932000+00:00"
    }
  ]
}
[
    RoutingTable(
        id=1,
        name="routing_table01",
        enabled=True,
        table_id=2,
        connection_id="iface:1",
        interface="eth0",
        gateway="192.168.10.1",
        routes=[
            Route(
                type="include",
                addr="192.127.2.10",
                nexthop="192.127.2.200"
            ),
            Route(
                type="exclude",
                addr="192.122.50.0/24",
                nexthop="192.122.50.200",
            )
        ],
        rules=[
            Rule(
                type="from",
                addr="192.168.0.0/24"
            ),
            Rule(
                type="to",
                addr="192.172.50.20"
            )
        ],
        created_at=DateTime(2018, 12, 13, 12, 20, 2, tzinfo=Timezone('+00:00')),
        updated_at=DateTime(2018, 12, 13, 12, 20, 2, tzinfo=Timezone('+00:00'))
    ),
    RoutingTable(
        id=2,
        name="routing_table02",
        enabled=True,
        table_id=3,
        connection_id="iface:2",
        interface="eth1",
        gateway="192.168.5.1",
        routes=[],
        rules=[],
        created_at=DateTime(2018, 12, 13, 14, 15, 2, tzinfo=Timezone('+00:00')),
        updated_at=DateTime(2018, 12, 13, 14, 15, 2, tzinfo=Timezone('+00:00'))
    )
]
[
  {
    id: 1,
    name: "routing_table01",
    enabled: true,
    tableId: 2,
    connectionId: "iface:1",
    interface: "eth0",
    gateway: "192.168.10.1",
    routes: [
      {
        type: "include",
        addr: "192.127.2.10",
        nexthop: "192.127.2.200",
      },
      {
        type: "exclude",
        addr: "192.122.50.0/24",
        nexthop: "192.122.50.200",
      }
    ],
    rules: [
      {
        type: "from",
        addr: "192.168.0.0/24"
      },
      {
        type: "to",
        addr: "192.172.50.20"
      }
    ],
    createdAt: "2018-12-13T12:20:02.000Z",
    updatedAt: "2018-12-13T12:20:02.000Z"
  },
  {
    id: 2,
    name: "routing_table02",
    enabled: true,
    tableId: 3,
    connectionId: "iface:2",
    interface: "eth1",
    gateway: "192.168.5.1",
    routes: [],
    rules: [],
    createdAt: "2018-12-13T14:15:02.000Z",
    updatedAt: "2018-12-13T14:15:02.000Z"
  }
];

Buscar tabela de roteamento

API de consulta de tabela de roteamento

GET /api/sdwan/routing/tables/id

Exemplo de requisição

GET /api/sdwan/routing/tables/1 HTTP/1.1
Host: api.exemplo.com
Accept: application/json
Authorization: Bearer <Access-Token>
response = sdk.sdwan.get_routing_table(id=1)
print(response.payload)
const response = sdk.sdwan.getRoutingTable({ id: 1 });
console.log(response.payload);

Exemplo de resposta

HTTP/1.1 200 OK
Content-Type: application/json

{
  "id": 1,
  "name": "routing_table01",
  "enabled": true,
  "table_id": 2,
  "connection_id": "iface:1",
  "interface": "eth0",
  "gateway": "192.168.10.1",
  "routes": [
    {
      "type": "include",
      "addr": "192.127.2.10",
      "nexthop": "192.127.2.200"
    },
    {
      "type": "exclude",
      "addr": "192.122.50.0/24",
      "nexthop": "192.122.50.200",
    }
  ],
  "rules": [
    {
      "type": "from",
      "addr": "192.168.0.0/24"
    },
    {
      "type": "to",
      "addr": "192.172.50.20"
    }
  ],
  "created_at": "2018-12-13T12:20:02.932000+00:00",
  "updated_at": "2018-12-13T12:20:02.932000+00:00"
}
RoutingTable(
    id=1,
    name="routing_table01",
    enabled=True,
    table_id=2,
    connection_id="iface:1",
    interface="eth0",
    gateway="192.168.10.1",
    routes=[
        Route(
            type="include",
            addr="192.127.2.10",
            nexthop="192.127.2.200"
        ),
        Route(
            type="exclude",
            addr="192.122.50.0/24",
            nexthop="192.122.50.200",
        )
    ],
    rules=[
        Rule(
            type="from",
            addr="192.168.0.0/24"
        ),
         Rule(
            type="to",
            addr="192.172.50.20"
        )
    ],
    created_at=DateTime(2018, 12, 13, 12, 20, 2, tzinfo=Timezone('+00:00')),
    updated_at=DateTime(2018, 12, 13, 12, 20, 2, tzinfo=Timezone('+00:00')),
)
{
  id: 1,
  name: "routing_table01",
  enabled: true,
  tableId: 2,
  connectionId: "iface:1",
  interface: "eth0",
  gateway: "192.168.10.1",
  routes: [
    {
      type: "include",
      addr: "192.127.2.10",
      nexthop: "192.127.2.200"
    },
    {
      type: "exclude",
      addr: "192.122.50.0/24",
      nexthop: "192.122.50.200",
    }
  ],
  rules: [
    {
      type: "from",
      addr: "192.168.0.0/24"
    },
    {
      type: "to",
      addr: "192.172.50.20"
    }
  ],
  createdAt: "2018-12-13T12:20:02.000Z",
  updatedAt: "2018-12-13T12:20:02.000Z"
}

Criar tabela de roteamento

API de criação de tabela de roteamento

POST /api/sdwan/routing/tables

Exemplo de requisição

POST /api/sdwan/routing/tables HTTP/1.1
Host: api.exemplo.com
Content-Type: application/json
Accept: application/json
Authorization: Bearer <Access-Token>

{
  "name": "routing_table01",
  "enabled": true,
  "table_id": 2,
  "connection_id": "iface:1",
  "routes": [
    {
      "type": "include",
      "addr": "192.127.2.10",
      "nexthop": "192.127.2.251"
    }
  ],
  "rules": [
    {
      "type": "from",
      "addr": "192.168.0.0/24"
    },
    {
      "type": "to",
      "addr": "192.172.50.20"
    }
  ],
  "apply": true,
}
from itflex_sdk.sdwan.types import CreateRoutingTableRequest, Route, Rule

request = CreateRoutingTableRequest(
    name="routing_table01",
    enabled=True,
    table_id=2,
    connection_id="iface:1",
    routes=[
        Route(
            type="include",
            addr="192.127.2.10",
            nexthop="192.127.2.251"
        )
    ],
    rules=[
        Rule(
            type="from",
            addr="192.168.0.0/24"
        ),
        Rule(
            type="to",
            addr="192.172.50.20"
        ),
    ],
    apply=True,
)
response = sdk.sdwan.create_routing_table(request)
print(response.payload)
const routingTable = sdk.sdwan.types.RoutingTable();
routingTable.name = "routing_table01";
routingTable.enabled = true;
routingTable.tableId = 2;
routingTable.connectionId = "iface:1";
routingTable.routes = [
  { type: "include", addr: "192.127.2.10", nexthop: "192.127.2.251" }
];
routingTable.rules = [
  { type: "from", addr: "192.168.0.0/24" },
  {type: "to", addr: "192.172.50.20"},
];
routingTable.apply = false;

const response = sdk.sdwan.createRoutingTable(routingTable);
console.log(response.payload);

Exemplo de resposta

HTTP/1.1 200 OK
Content-Type: application/json

{
  "id": 1,
  "name": "routing_table01",
  "enabled": true,
  "table_id": 2,
  "connection_id": "iface:1",
  "interface": "eth0",
  "gateway": "192.168.10.1",
  "routes": [
    {
      "type": "include",
      "addr": "192.127.2.10",
      "nexthop": "192.127.2.251"
    }
  ],
  "rules": [
    {
      "type": "from",
      "addr": "192.168.0.0/24"
    },
    {
      "type": "to",
      "addr": "192.172.50.20"
    }
  ],
  "created_at": "2018-12-13T12:20:02.932000+00:00",
  "updated_at": "2018-12-13T12:20:02.932000+00:00"
}
RoutingTable(
    id=1,
    name="routing_table01",
    enabled=True,
    table_id=2,
    connection_id="iface:1",
    interface="eth0",
    gateway="192.168.10.1",
    routes=[
        Route(
            type="include",
            addr="192.127.2.10",
            nexthop="192.127.2.251"
        )
    ],
    rules=[
        Rule(
            type="from",
            addr="192.168.0.0/24"
        ),
        Rule(
            type="to",
            addr="192.172.50.20"
        )
    ],
    created_at=DateTime(2018, 12, 13, 12, 20, 2, tzinfo=Timezone('+00:00')),
    updated_at=DateTime(2018, 12, 13, 12, 20, 2, tzinfo=Timezone('+00:00'))
)
{
  id: 1,
  name: "routing_table01",
  enabled: true,
  tableId: 2,
  connectionId: "iface:1",
  interface: "eth0",
  gateway: "192.168.10.1",
  routes: [
    {
      type: "include",
      addr: "192.127.2.10",
      nexthop: "192.127.2.251"
    }
  ],
  rules: [
    {
      type: "from",
      addr: "192.168.0.0/24"
    },
    {
      type: "to",
      addr: "192.172.50.20"
    }
  ],
  createdAt: "2018-12-13T12:20:02.000Z",
  updatedAt: "2018-12-13T12:20:02.000Z"
}

Editar tabela de roteamento

API de edição de tabela de roteamento

PUT /api/sdwan/routing/tables/id

Exemplo de requisição

PUT /api/sdwan/routing/tables/3 HTTP/1.1
Host: api.exemplo.com
Content-Type: application/json
Accept: application/json
Authorization: Bearer <Access-Token>

{
  "enabled": true,
  "table_id": 2,
  "connection_id": "iface:1",
  "routes": [],
  "rules": [
    {
      "type": "from",
      "addr": "192.168.0.0/24"
    }
  ],
  "apply": true,
}
from itflex_sdk.sdwan.types import UpdateRoutingTableRequest, Rule

request = UpdateRoutingTableRequest(
    id=1,
    renabled=True,
    table_id=2,
    connection_id="iface:1",
    routes=[],
    rules=[
        Rule(
            type="from",
            addr="192.168.0.0/24"
        )
    ],
    apply=True,
)
response = sdk.sdwan.update_routing_table(request)
print(response.payload)
const routingTable = {
  id: 1,
  enabled: true,
  tableId: 2,
  connectionId: "iface:1",
  routes: [],
  rules: [{ type: "from", addr: "192.168.0.0/24" }],
  apply: true,
};
const response = sdk.sdwan.updateRoutingTable(routingTable);
console.log(response.payload);

Exemplo de resposta

HTTP/1.1 200 OK
Content-Type: application/json

{
  "id": 1,
  "name": "routing_table01",
  "enabled": true,
  "table_id": 2,
  "connection_id": "iface:1",
  "interface": "eth0",
  "gateway": "192.168.10.1",
  "routes": [],
  "rules": [
    {
      "type": "from",
      "addr": "192.168.0.0/24"
    }
  ],
  "created_at": "2018-12-14T09:20:02.932000+00:00",
  "updated_at": "2018-12-14T10:30:02.932000+00:00"
}
RoutingTable(
    id=1,
    name="routing_table01",
    enabled=True,
    table_id=2,
    connection_id="iface:1",
    interface="eth0",
    gateway="192.168.10.1",
    routes=[],
    rules=[
        Rule(type="from", addr="192.168.0.0/24")
    ],
    created_at=DateTime(2018, 12, 14, 9, 20, 2, tzinfo=Timezone('+00:00')),
    updated_at=DateTime(2018, 12, 14, 10, 30, 2, tzinfo=Timezone('+00:00'))
)
{
  id: 1,
  name: "routing_table01",
  enabled: true,
  tableId: 2,
  connectionId: "iface:1",
  interface: "eth0",
  gateway: "192.168.10.1",
  routes: [],
  rules: [
    { type: "from", addr: "192.168.0.0/24" }
  ],
  createdAt: "2018-12-14T09:20:02.000Z",
  updatedAt: "2018-12-14T10:30:02.000Z"
}

Excluir tabela de roteamento

API de exclusão de tabela de roteamento

DELETE /api/sdwan/routing/tables/id

Exemplo de requisição

DELETE /api/sdwan/routing/tables/1 HTTP/1.1
Host: api.exemplo.com
Accept: application/json
Authorization: Bearer <Access-Token>
response = sdk.sdwan.delete_routing_table(id=1)
const response = sdk.sdwan.deleteRoutingTable({ id: 1 });

Exemplo de resposta

HTTP/1.1 200 OK
Content-Type: application/json

Aplicar tabelas de roteamento

API de aplicação de tabelas de roteamento

POST /api/sdwan/routing/tables/apply

Exemplo de requisição

POST /api/sdwan/routing/tables/apply HTTP/1.1
Host: api.exemplo.com
Accept: application/json
Authorization: Bearer <Access-Token>
response = sdk.sdwan.apply_routing_tables()
const response = sdk.sdwan.applyRoutingTables();

Exemplo de resposta

HTTP/1.1 200 OK
Content-Type: application/json

Formato dos dados

Parâmetros da url

Campo Descrição
id int

Identificador da tabela de roteamento

Requisição

Campo Descrição
name stringrequerido único

Nome da tabela de roteamento.

Não editável.

Tamanho máximo: 30 caracteres

enabled boolrequerido

Flag que determina se a tabela de rotemento está habilitada ou desabilitada.

table_id intrequerido único

Identificador da tabela de roteamento do Linux.

Este valor também deve ser usado para realizar a marcação de pacotes via iptables (ação MARK).

Deve ser sempre um número entre 2 e 500.

connection_id stringúnico

Identificador da conexão.

Tipos de conexões validas:

  • Interfaces de rede: wan, lan, dmz, guest
  • Instâncias OpenVPN: ovpn-server
interface stringúnico

Nome da interface de rede.

Requerido se o campo connection_id não estiver preenchido.

gateway string

IP do gateway da interface de rede.

Requerido se o campo connection_id não estiver preenchido.

routes array<object>

Lista de rotas que serão alteradas das redes da tabela de roteamento padrão.

Valores duplicados nesta lista devem ser removidos automaticamente.

Formato: {"type": "exclude", "addr": "192.168.121.0/24", "nexthop": "192.168.121.200"}

  • type: Tipo de rota. Os tipos válidos são include e exclude.
  • addr: Endereço da rota.
  • nexthop: Próximo salto da rota incluída. Requerido independente do tipo de rota selecionado.
rules array<object>

Lista de regras de roteamento da tabela.

Formato: {"type": "from", "addr": "192.168.0.0/24"}

  • type: Tipo da regra de roteamento. Os tipos válidos são: from e to.
  • addr: Endereço da regra de roteamento da política. Pode ser um IP ou uma rede.
apply bool

Flag que habilitada a aplicação da tabela de roteamento após salvar ou editar.

Resposta

Campo Descrição
id int

Identificador da tabela de roteamento

enabled bool

Flag que determina se a tabela de rotemento está habilitada ou desabilitada.

table_id int

Identificador da tabela de roteamento do Linux.

connection_id string

Identificador da conexão.

interface string

Nome da interface de rede.

gateway string

IP do gateway da interface de rede.

routes array<object>

Lista de rotas que serão alteradas das redes da tabela de roteamento padrão.

Formato: {"type": "exclude", "addr": "192.168.121.0/24", "nexthop": "192.168.121.200"}

rules array<object>

Lista de regras de roteamento da tabela.

Formato: {"type": "from", "addr": "192.168.0.0/24"}

created_at string

Data de criação

Formato: ISO-8601

updated_at string

Data da última edição

Formato: ISO-8601