Routing
- class sequence.network_management.routing.DistributedRoutingProtocol(owner: QuantumRouter, name: str)
Class to implement distributed routing protocol (OSPF-like protocol).
- name
label for protocol instance.
- Type:
str
- lsdb
link state database.
- Type:
LinkStateDB
- fsm
mapping of all neighbors’ name to its FSM.
- Type:
dict[str, NeighborFSM]
- link_cost
mapping of neighbor name to link cost.
- Type:
dict[str, float]
- adj_cost
mapping of neighbor name with 2-way hellos to link cost.
- Type:
dict[str, float]
- seq_number
sequence number for own LSA.
- Type:
int
- refresh_enabled
whether refreshing own LSA is enabled.
- Type:
bool
- last_originated_time
time of last originated LSA.
- Type:
int
- check_neighbor_liveness(neighbor: str, last_hello_time: int)
Check if neighbor is still alive.
- Parameters:
neighbor (str) – name of neighbor.
last_hello_time (int) – time of last hello received from neighbor.
- dbd_retransmit(neighbor: str, dbd_msg: DistRoutingMessage)
Retransmit the DBD message when timeout.
- Parameters:
neighbor (str) – name of neighbor.
dbd_msg (DistRoutingMessage) – the DBD message to be retransmitted.
- ensure_fsm(neighbor: str) NeighborFSM
Ensure FSM exists for a neighbor.
- Parameters:
neighbor (str) – name of a neighbor.
- Returns:
FSM for a neighbor.
- Return type:
NeighborFSM
- expire_lsa(last_originated_time: int)
Withdraw own LSA when it reaches max_age (if refresh is disabled).
- Parameters:
last_originated_time (int) – the previous origin time of the LSA.
- flood_to_all_neighbors(lsa: LSA, exclude_neighbor: str | None = None)
- Flood LSA to all neighbors with 2-way adjacency.
An LSU message containing the LSA is sent to each neighbor, except the excluded neighbor if specified.
- Parameters:
lsa (LSA) – LSA to be flooded.
exclude_neighbor (str | None) – neighbor to exclude from flooding.
- get_age(item: LSA | LSAHeader) int
Get age of LSA or LSAHeader.
- Parameters:
item (LSA | LSAHeader) – LSA or LSAHeader.
- Returns:
age of the item in picoseconds.
- Return type:
int
- handle_dbd(src: str, payload: DBDPayload)
- Handle DBD message from the neighbor.
Request any missing or outdated LSAs.
- Parameters:
src (str) – name of a source node.
payload (DBDPayload) – payload of a DBD message.
- handle_hello(src: str, payload: HelloPayload)
Handle HELLO message from a neighbor.
- Parameters:
src (str) – name of the source node.
payload (HelloPayload) – payload of HELLO message.
- handle_lsack(src: str, payload: LSAckPayload)
Handle LSAck message from the neighbor.
- Parameters:
src (str) – name of a source node.
payload (LSAckPayload) – payload of LSAck message.
- handle_lsr(src: str, payload: LSRPayload)
Handle LSR message from a neighbor. Send back the requested LSAs.
- Parameters:
src (str) – name of the source node.
payload (LSRPayload) – payload of LSR message.
- handle_lsu(src: str, payload: LSUPayload)
Handle LSU message from a neighbor.
- Parameters:
src (str) – name of source node.
payload (LSUPayload) – payload of LSU message.
- init()
Initialize: 1) the FSM for each neighbor 2) the first hello event 3) the first LSA refresh event (enabled by default)
- originate() LSA
Originate and return its LSA, meanwhile increment its sequence number.
- Returns:
the originated LSA.
- Return type:
LSA
- originate_and_flood()
Originate own LSA and flood to all neighbors with 2-way adjacency.
- originate_withdrawal() LSA
Originate a withdrawal LSA (MAX_AGE) for this router.
- received_message(src: str, msg)
Receive the distributed routing message from another node.
- Parameters:
src (str) – name of the source node.
msg (Message) – message received.
- refresh_lsa(delay: int)
Refresh own LSA now via flooding, then schedule the next refresh after delay.
- Parameters:
delay (int) – the delay (picoseconds) for sending the next refresh event.
- run_spf() dict[str, str]
Run Shortest Path First (SPF) algorithm to compute routing table.
- Returns:
mapping of destination to next hop.
- Return type:
forwarding_table (dict[str, str])
- schedule_dbd_resend(neighbor: str, dbd_msg: DistRoutingMessage)
Schedule DBD retransmission (currently on for the master node, because the master initiates the exchange).
- Parameters:
neighbor (str) – name of neighbor.
dbd_msg (DistRoutingMessage) – the DBD message to be retransmitted.
- send_dbd(neighbor: str) DistRoutingMessage
Send DBD message to neighbor.
- Parameters:
neighbor (str) – name of neighbor.
- Returns:
the DBD message sent.
- Return type:
DistRoutingMessage
- send_hello(delay: int)
- Send HELLO message to all neighbors now,
and schedule the next send_hello after delay (picoseconds).
- Parameters:
delay (int) – the delay (picoseconds) for sending the next send_hello event.
- set_state(neighbor: str, new_state: str)
Set the state of the neighbor FSM.
- Parameters:
neighbor (str) – name of neighbor.
new_state (str) – new state to set.
- start_exstart(neighbor: str)
- Start ExStart state with neighbor.
A master node is elected and begin DBD exchange.
- Parameters:
neighbor (str) – name of neighbor.
- class sequence.network_management.routing.RoutingProtocol(owner: QuantumRouter, name: str, protocol_type: str)
Abstract base class for routing protocols.
- classmethod create(owner: QuantumRouter, name: str, protocol_type) RoutingProtocol
Factory method to create a routing protocol instance using the global routing type.
- Parameters:
owner (QuantumRouter) – node protocol is attached to.
name (str) – name of protocol instance.
- Returns:
instance of the routing protocol.
- Return type:
- property forwarding_table: dict[str, str]
Returns the forwarding table.
- Returns:
forwarding table in format {name of destination node: name of next node}.
- Return type:
dict[str, str]
- abstractmethod init()
Initialize routing protocol. Must be implemented by subclasses.
- abstractmethod received_message(src: str, msg: Message)
Method to handle received messages. Must be implemented by subclasses.
- classmethod register(protocol_type: str, protocol_class: type[RoutingProtocol] = None)
Register a routing protocol class.
- Parameters:
protocol_type (str) – type of the routing protocol.
protocol_class (type['RoutingProtocol']) – class of the routing protocol. Defaults to None.
- set_forwarding_table(forwarding_table: dict[str, str])
Sets the whole forwarding table.
- Parameters:
forwarding_table (dict[str, str]) – forwarding table in format {name of destination node: name of next node}.
- update_forwarding_rule(dst: str, next_node: str)
- Updates dst to map to next_node in forwarding table.
If dst not in forwarding table, effectively adds a new rule to the forwarding table.
- Parameters:
dst (str) – name of destination node.
next_node (str) – name of next hop node.
- class sequence.network_management.routing.StaticRoutingProtocol(owner: QuantumRouter, name: str)
Class to update forwarding table manually.
The StaticRoutingProtocol class writes to the forwarding table (from the NetworkManager). Static in this context means that the forwarding table is manually configured (by a network administrator), not automatically updated via a routing protocol (i.e. computer program).
- init()
Initialize routing protocol. Must be implemented by subclasses.