Bgp protection

Here, we define functions for bgp packet packet protection.

include byte_stream
include bgp_type
include collections
Because of packet coalescing, we need a custom serializer and deserializer for protected packets. In particular, we need to look at the length field of the long form packets to find the packet boundaries within a datagram.

module bgp_messages = {
    instance idx : unbounded_sequence
    instance arr : array(idx,stream_data)
}
The serializer just concatenates the packets

object bgp_prot_ser = {}

<<< member

    class `bgp_prot_ser`;

>>>

<<< impl

    class `bgp_prot_ser` : public ivy_binary_ser_128 {
    public:

        void open_list(int) {
        }

        virtual void  set(int128_t res) {
            setn(res,1);
        }
    };

>>>
The deserializer is tricker. It looks at the first byte of the packet to determine if it is a long or short packet. For long packets, it computes the total length based on the header bytes and the payload length field. This is a bit redundant with the above code, however this can't be helped as there is no way for the deserializer to have access to the ivy object.

object bgp_prot_deser = {}

<<< member

    class `bgp_prot_deser`;

>>>

<<< impl

    class `bgp_prot_deser` : public ivy_binary_deser_128 {
        int data_remaining;
    public:
        bgp_prot_deser(const std::vector<char> &inp) : ivy_binary_deser_128(inp) {
            data_remaining = inp.size();
            std::cerr << "bgp_prot_deser data_remaining = " << data_remaining << "\n";
        }

        void  get(int128_t &res) {
            getn(res,1);
            std::cerr << "bgp_prot_deser data_remaining = " << data_remaining << "\n";
        }

        unsigned char peek(unsigned p) {
            return more(p-pos+1) ? inp[p] : 0;
        }

        void open_list() {
            return;
        }

        bool open_list_elem() {
            bool res = data_remaining--> = 0;
            std::cerr << "bgp_prot_deser data_remaining = " << data_remaining << "\n";
            return res;
        }
        void close_list_elem() {
        }
    };

>>>