OpenBMP / obmp-psql

New OpenBMP PostgreSQL consumer and database
BSD 3-Clause "New" or "Revised" License
6 stars 9 forks source link

Prefix History doesn't separate between AdjRIB-IN/OUT and Pre/Post-policy updates for the same prefix #9

Open v1shnya opened 1 year ago

v1shnya commented 1 year ago

In the file "1_base.sql" the table ip_rib contains isPrePolicy and isAdjRibIn fields

CREATE TABLE ip_rib (
.....
    isPrePolicy             boolean             NOT NULL DEFAULT true,
    isAdjRibIn              boolean             NOT NULL DEFAULT true,
);

At same time, the table ip_rib_log lacks those fields, should be added

CREATE TABLE ip_rib_log (
    id                      bigserial           NOT NULL,
    base_attr_hash_id       uuid                NOT NULL,
    timestamp               timestamp(6)        without time zone default (now() at time zone 'utc') NOT NULL,
    peer_hash_id            uuid                NOT NULL,
    prefix                  inet                NOT NULL,
    prefix_len              smallint            NOT NULL,
    origin_as               bigint              NOT NULL,
    isWithdrawn             boolean             NOT NULL
) TABLESPACE timeseries;

v_ip_routes_history as dependent on ip_rib_log should also containthose fields, file "8_views.sql"

And, update function of ip_rib_log table, file "9_triggers.sql", should include new.isPrePolicy and new.isAdjRibIn values!

CREATE OR REPLACE FUNCTION t_ip_rib_update()
    RETURNS trigger AS $$
BEGIN
    IF (new.isWithdrawn) THEN
        INSERT INTO ip_rib_log (isWithdrawn,prefix,prefix_len,base_attr_hash_id,peer_hash_id,origin_as,timestamp)
        VALUES (true,new.prefix,new.prefix_len,old.base_attr_hash_id,new.peer_hash_id,
                old.origin_as,new.timestamp);
    ELSE
        INSERT INTO ip_rib_log (isWithdrawn,prefix,prefix_len,base_attr_hash_id,peer_hash_id,origin_as,timestamp)
        VALUES (false,new.prefix,new.prefix_len,new.base_attr_hash_id,new.peer_hash_id,
                new.origin_as,new.timestamp);
    END IF;

    RETURN NEW;
END;
$$ LANGUAGE plpgsql;
TimEvens commented 1 year ago

@v1shnya, Thanks. They can be added to the ip_rib_log table. While they are not there now, a log entry will be added because the rib hash ID includes those values in the hash.