QuISP
Loading...
Searching...
No Matches
Ospf.h
Go to the documentation of this file.
1#pragma once
2
16#include <omnetpp.h>
17#include <algorithm>
18#include <limits>
19#include <memory>
20#include <queue>
21#include <vector>
22#include "omnetpp/cexception.h"
23
24namespace quisp::modules::ospf {
25
26class LinkStateDatabase;
27struct LinkStateAdvertisement;
28struct SummaryLinkStateAdvertisement;
29struct OspfNeighborInfo;
30enum class OspfState;
31
32using NodeAddr = int;
33using RouterIds = std::vector<int>;
34using NeighborTable = std::map<NodeAddr, OspfNeighborInfo>;
35using LinkStateDatabaseSummary = std::vector<SummaryLinkStateAdvertisement>;
36using LinkStateUpdate = std::vector<LinkStateAdvertisement>;
37
38enum class OspfState { DOWN = 0, INIT = 1, TWO_WAY = 2, EXSTART = 3, EXCHANGE = 4, LOADING = 5, FULL = 6 };
39
42 // address that router needs in order to send packet to neighbor router
43 // qnic_address in case of Quantum Routing Table
44 int hop_address = -1;
46 double cost;
47
48 OspfNeighborInfo(int _router_id) : router_id(_router_id) {}
49 OspfNeighborInfo(int _hop_address, OspfState _state) : hop_address(_hop_address), state(_state) {}
50 OspfNeighborInfo(int _hop_address, OspfState _state, double _cost) : hop_address(_hop_address), state(_state), cost(_cost) {}
51 OspfNeighborInfo(int _router_id, int _hop_address, double _cost) : router_id(_router_id), hop_address(_hop_address), cost(_cost) {}
52 OspfNeighborInfo(int _router_id, int _hop_address, OspfState _state, double _cost) : router_id(_router_id), hop_address(_hop_address), state(_state), cost(_cost) {}
53 OspfNeighborInfo() = default;
54};
55
68
76 LinkStateAdvertisement(NodeAddr _id, NodeAddr _origin_id, NeighborTable _neighbor_table) : SummaryLinkStateAdvertisement(_id, _origin_id, 0), neighbor_nodes(_neighbor_table) {}
77 LinkStateAdvertisement(NodeAddr _id, NodeAddr _origin_id, int _age, NeighborTable _neighbor_table)
78 : SummaryLinkStateAdvertisement(_id, _origin_id, _age), neighbor_nodes(_neighbor_table) {}
80};
81
89 protected:
93 struct Vertex;
94
100 struct VertexMinPriority;
101
102 using VertexSharedPtr = std::shared_ptr<Vertex>;
103 using VertexMap = std::map<NodeAddr, VertexSharedPtr>;
104 using PriorityQueue = std::priority_queue<VertexSharedPtr, std::vector<VertexSharedPtr>, VertexMinPriority>;
105
106 public:
108
110
111 std::map<NodeAddr, int> generateRoutingTableFromGraph(NodeAddr source) const;
112
113 RouterIds identifyMissingLinkStateAdvertisementId(const LinkStateDatabaseSummary& lsdb_summary_from_neighbor) const;
114 virtual bool needsFullLinkStateAdvertisementOf(const SummaryLinkStateAdvertisement& summary_lsa) const;
115 LinkStateUpdate getLinkStateUpdatesFor(const RouterIds& requests, int my_address) const;
117 bool hasLinkStateAdvertisementOf(NodeAddr router) const;
118
119 protected:
120 int getHopAddressToNeighbor(NodeAddr src, NodeAddr neighbor) const;
121 NodeAddr getSecondNodeInPathToDestNode(NodeAddr source_id, NodeAddr dst_id, const VertexMap& vertices) const;
122
123 virtual const VertexMap dijkstraAlgorithm(NodeAddr source_id) const;
125 double weight(NodeAddr node1, NodeAddr node2) const;
127
128 protected:
129 std::map<NodeAddr, LinkStateAdvertisement> link_state_database;
131
132 struct Vertex {
136 static constexpr int no_prev_node = -1;
137 Vertex(LinkStateAdvertisement _lsa) : node_id(_lsa.lsa_origin_id), distance_from_source(std::numeric_limits<double>::max()), prev_node_in_path(no_prev_node) {}
138 Vertex() = default;
139 };
140
142 bool operator()(VertexSharedPtr const l, VertexSharedPtr const r) const noexcept { return l->distance_from_source > r->distance_from_source; }
143 };
144};
145} // namespace quisp::modules::ospf
Definition Ospf.cc:3
std::vector< LinkStateAdvertisement > LinkStateUpdate
Definition Ospf.h:36
std::map< NodeAddr, OspfNeighborInfo > NeighborTable
Definition Ospf.h:34
int NodeAddr
Definition Ospf.h:32
OspfState
Definition Ospf.h:38
std::vector< int > RouterIds
Definition Ospf.h:33
std::vector< SummaryLinkStateAdvertisement > LinkStateDatabaseSummary
Definition Ospf.h:35
Definition QNIC.h:49
OspfNeighborInfo(int _router_id, int _hop_address, double _cost)
Definition Ospf.h:51
OspfNeighborInfo(int _router_id, int _hop_address, OspfState _state, double _cost)
Definition Ospf.h:52
OspfNeighborInfo(int _hop_address, OspfState _state)
Definition Ospf.h:49
OspfNeighborInfo(int _hop_address, OspfState _state, double _cost)
Definition Ospf.h:50
double cost
Definition Ospf.h:46
int hop_address
Definition Ospf.h:44
NodeAddr router_id
Definition Ospf.h:41
OspfState state
Definition Ospf.h:45
OspfNeighborInfo(int _router_id)
Definition Ospf.h:48