Segment Routing over IPv6 is a next-generation IP bearer protocol.
In traditional IP routing, an IP packet sent from a source host goes through multiple routers and then reaches the destination host. Each router checks the destination IP address inside the IP packet header. Then sent the packet to the next router which is closer to the destination. Technically, we call the next closest router “next hop”. Of course, the “next hop” has to be a neighbor of the current router in the graph.
Routers typically maintain a routing table, lists the next hop to particular network destinations. Whenever a new IP packet comes, a router examines the packet header’s destination IP address and compares it against a routing table to determine the packet’s best next hop.
No wonder looking up routing tables takes time, if an IP packet goes through K routers to reach the destination, the looking up process will happen K times at each router. That’s one reason why there is high latency between two distant hosts.
In a segment routed network, an IP packet may be prepended a header that contains a list of “segments”, which are instructions that are executed on subsequent nodes in the network. These instructions may be forwarding instructions, such as an instruction to forward a packet to a specific destination or interface.
We can consider the internet as a directed graph.
For example, consider the following topology.
±+ #2 ±+ #1 ±+
|A±------------>|C±--------->|D|
+++ +++ ±+
| |
| |
| |
| |
| |
| |
#1| |
| |#2
| |
| |
| |
v |
±+ |
|B|<--------------+
±+
Router A has two out-edges, its #1 out edge is connected to Router B and its #2 out edge is connected to Router C.
Router C has two out-edges, too. Its #1 out edge is connected to Router D and its #2 out edge is connected to Router B.
Suppose A is going to send a packet to Router D. The only path in this graph is A->C->D. The link used is the #2 out edge of A, and the #1 out edge of C.
A is going to receive a list of instructions along with the packet if segment routing protocol is enabled:
The first instruction is to forward the package by #2 out-edge of the current vertex (Router A), the second instruction is to forward the package by #1 out-edge of the current vertex (Router C). Hence, the routers will check the instructions in the packet header to decide the next hop. The routing table looking up is no longer needed.
Now we have a network log recording the SRv6 packet headers used during last month. Unfortunately, the destination addresses get lost, can you recover them from the forward instructions?
Input
There are T test cases in this problem.
The first line has one integer T.
For each test case: