==========
Version 1
==========

The  REST API lives at the ``/v1`` endpoint and responsds to GET, POST, PUT, and DELETE.

Root
~~~~

Used to check the API status, if it can work.


**Example request**:

.. code-block:: bash

    GET /v1

**Example response**:

It will return the status of this version of API.

.. code-block:: json

  {
    "status": "stable",
    "updated": "2015-01-22T00:00:00Z",
    "version": "v1"
  }


Peer's Information
~~~~~~~~~~~~~~~~~~

Try to get peer's configuration and running information.

One Peers
+++++++++

Get one peer's configuration and running information.

.. code-block:: bash

    GET /v1/peer/<peer_ip_address>/state

**Example response**:

.. code-block:: json

    {
        "peer": {
            "fsm": "ESTABLISHED",
            "local_addr": "10.75.44.11",
            "local_as": 23650,
            "remote_addr": "10.124.1.245",
            "remote_as": 23650,
            "uptime": 7.913731813430786
        }
    }

Get send/recieve version
++++++++++++++++++++++++

Get peer's send/recieve version .

.. code-block:: bash

    GET /v1/peer/<peer_ip_address>/version/<action>
    action : send, received

**Example response**:

.. code-block:: json

    {
        "version": {
            "flowspec": 0,
            "ipv4": 0,
            "mpls_vpn": 0,
            "sr_policy": 0
        }
    }

Message Statistic
+++++++++++++++++

Get the BGP message sending and receiving number statistic.

.. code-block:: bash

    GET /v1/peer/<peer_ip_address>/statistic

**Example response**:

.. code-block:: json

      {
          "receive": {
              "Keepalives": 3,
              "Notifications": 0,
              "Opens": 1,
              "Route Refresh": 0,
              "Updates": 5
          },
          "send": {
              "Keepalives": 3,
              "Notifications": 0,
              "Opens": 1,
              "Route Refresh": 0,
              "Updates": 0
          }
      }

Send Message
~~~~~~~~~~~~

Route Refresh
+++++++++++++

Send BGP route refresh message to peer.

==== ====== ===========
afi  safi   Description
==== ====== ===========
1    1      IPv4 unicast
1    128    IPv4 MPLS VPN
2    1      IPv6 unicast
2    128    IPv6 MPLS VPN
==== ====== ===========

.. code-block:: bash

    POST /v1/peer/<peer_ip_address>/send/route-refresh

POST data format

.. code-block:: json

    {
        "afi": 1,
        "safi": 1,
        "res": 0
    }

**Example response**:

.. code-block:: json

    {
        "status": true
    }

Update
++++++

Send BGP update message to peer

.. code-block:: bash

    POST /v1/peer/<peer_ip_address>/send/update


POST data format for update

.. code-block:: json

    {
        "attr":{
            "1": 0,
            "2": [],
            "3": "192.0.2.1",
            "5": 100,
            "8": ["NO_EXPORT"]
    },
        "nlri": ["172.20.1.0/24", "172.20.2.0/24"]
    }

POST data format for withdraw

.. code-block:: json

    {
        "withdraw": ["172.20.1.0/24", "172.20.2.0/24"]
    }

**Example response**:

.. code-block:: json

    {
        "status": true
    }

Manual start and stop
~~~~~~~~~~~~~~~~~~~~~

manual start
++++++++++++

 Try to manual start BGP session

.. code-block:: bash

    GET /v1/peer/<peer_ip_address>/manual-start

**Example response**:

.. code-block:: json

    {
        "status": true
    }

manual stop
+++++++++++

 Try to manual start BGP session

.. code-block:: bash

    GET /v1/peer/<peer_ip_address>/manual-stop

**Example response**:

.. code-block:: json

    {
        "status": true
    }

Adj Rib In Search
~~~~~~~~~~~~~~~~~~~

search Adj Rib In (received RIB) based on address family.

IPv4 unicast
++++++++++++++

.. code-block:: bash

    POST /v1/peer/{{peer}}/adj-rib-in?afi_safi=ipv4

POST data format:

.. code-block:: json

    {
        "data": ["186.96.174.0","199.36.240.0/22"]
    }

``data`` is prefix or IP list, for prefix format, we use exactly match, for IP format, we use prefix longest match

The response example: (each ip/prefix match results with attributes and prefix)

.. code-block:: json

    {
        "data": {
            "186.96.174.0": {
                "attr": {
                    "1": 0,
                    "2": [
                        [
                            2,
                            [
                                27418,
                                8100,
                                3491,
                                3356,
                                3549,
                                7049,
                                11750
                            ]
                        ]
                    ],
                    "3": "10.75.44.254",
                    "5": 100,
                    "8": [
                        "3356:3",
                        "3356:86",
                        "3356:575",
                        "3356:666",
                        "3356:2003",
                        "3549:4813",
                        "3549:34032",
                        "8100:50",
                        "29761:50"
                    ],
                    "9": "172.17.0.7",
                    "10": [
                        "2.2.2.2"
                    ]
                },
                "prefix": "186.96.174.0/24"
            },
            "199.36.240.0/22": {
                "attr": {
                    "1": 0,
                    "2": [
                        [
                            2,
                            [
                                27418,
                                8100,
                                174,
                                13238
                            ]
                        ]
                    ],
                    "3": "10.75.44.254",
                    "5": 100,
                    "7": [
                        13238,
                        "100.43.92.159"
                    ],
                    "8": [
                        "174:21001",
                        "174:22013",
                        "8100:50",
                        "29761:50"
                    ],
                    "9": "172.17.0.7",
                    "10": [
                        "2.2.2.2"
                    ]
                },
                "prefix": "199.36.240.0/22"
            }
        },
        "status": true
    }


Adj Rib out Search
~~~~~~~~~~~~~~~~~~~

search Adj Rib out (sended RIB) based on address family.

IPv4 unicast
++++++++++++++

.. code-block:: bash

    POST /v1/peer/{{peer}}/adj-rib-out?afi_safi=ipv4

POST data format:

.. code-block:: json

    {
        "data": ["186.96.174.0/24","199.36.240.0/22"]
    }

``data`` is prefix list.

The response example: (each ip/prefix match results with attributes and prefix)

.. code-block:: json

    {
        "data": {
            "186.96.174.0/24": {
                "attr": {
                    "1": 0,
                    "2": [
                        [
                            2,
                            [
                                27418,
                                8100,
                                3491,
                                3356,
                                3549,
                                7049,
                                11750
                            ]
                        ]
                    ],
                    "3": "10.75.44.254",
                    "5": 100,
                    "8": [
                        "3356:3",
                        "3356:86",
                        "3356:575",
                        "3356:666",
                        "3356:2003",
                        "3549:4813",
                        "3549:34032",
                        "8100:50",
                        "29761:50"
                    ],
                    "9": "172.17.0.7",
                    "10": [
                        "2.2.2.2"
                    ]
                },
                "prefix": "186.96.174.0/24"
            },
            "199.36.240.0/22": {
                "attr": {
                    "1": 0,
                    "2": [
                        [
                            2,
                            [
                                27418,
                                8100,
                                174,
                                13238
                            ]
                        ]
                    ],
                    "3": "10.75.44.254",
                    "5": 100,
                    "7": [
                        13238,
                        "100.43.92.159"
                    ],
                    "8": [
                        "174:21001",
                        "174:22013",
                        "8100:50",
                        "29761:50"
                    ],
                    "9": "172.17.0.7",
                    "10": [
                        "2.2.2.2"
                    ]
                },
                "prefix": "199.36.240.0/22"
            }
        },
        "status": true
    }