23 #include "goby/common/logger.h" 24 #include "goby/util/as.h" 32 void goby::acomms::RouteManager::set_cfg(
const protobuf::RouteManagerConfig& cfg)
38 void goby::acomms::RouteManager::merge_cfg(
const protobuf::RouteManagerConfig& cfg)
44 void goby::acomms::RouteManager::process_cfg()
46 glog.is(DEBUG1) &&
glog << group(
"goby::acomms::route")
47 <<
"Route is: " << cfg_.route().DebugString() << std::endl;
50 void goby::acomms::RouteManager::handle_in(
const protobuf::QueuedMessageMeta& meta,
53 if (meta.dest() == modem_id)
56 glog.is(DEBUG1) &&
glog << group(
"goby::acomms::route") <<
"Incoming message " 57 << data_msg.GetDescriptor()->full_name()
58 <<
", can we route message to destination: " << meta.dest() <<
"?" 61 int next_hop = find_next_hop(modem_id, meta.dest());
65 uint32 subnet = next_hop & cfg_.subnet_mask();
66 glog.is(DEBUG1) &&
glog << group(
"goby::acomms::route")
67 <<
"Requeuing to proper subnet: " << subnet <<
" (" << std::hex
68 << next_hop <<
" & " << cfg_.subnet_mask() <<
")" << std::dec
70 if (!subnet_map_.count(subnet))
72 glog.is(DEBUG1) &&
glog << group(
"goby::acomms::route")
73 <<
"No subnet available for this message, ignoring." 78 subnet_map_[subnet]->push_message(data_msg, &meta);
82 glog.is(DEBUG1) &&
glog << group(
"goby::acomms::route")
83 <<
"Destination is not in route, ignoring." << std::endl;
87 int goby::acomms::RouteManager::route_index(
int modem_id)
89 for (
int i = 0, n = cfg_.route().hop_size(); i < n; ++i)
91 if (cfg_.route().hop(i) == modem_id)
97 void goby::acomms::RouteManager::handle_out(protobuf::QueuedMessageMeta* meta,
100 glog.is(DEBUG1) &&
glog << group(
"goby::acomms::route")
101 <<
"Trying to route outgoing message to destination: " << meta->dest()
104 int next_hop = find_next_hop(modem_id, meta->dest());
107 meta->set_dest(next_hop);
108 glog.is(DEBUG1) &&
glog << group(
"goby::acomms::route")
109 <<
"Set next hop to: " << meta->dest() << std::endl;
113 int goby::acomms::RouteManager::find_next_hop(
int us,
int dest)
115 int next_hop = find_next_route_hop(us, dest);
116 if (next_hop == -1 && cfg_.has_default_gateway())
118 next_hop = cfg_.default_gateway();
119 glog.is(DEBUG1) &&
glog << group(
"goby::acomms::route")
120 <<
"Using default gateway: " << next_hop << std::endl;
125 int goby::acomms::RouteManager::find_next_route_hop(
int us,
int dest)
127 int current_route_index = route_index(us);
129 if (current_route_index == -1)
131 glog.is(DEBUG1) &&
glog << group(
"goby::acomms::route")
132 <<
"Current modem id is not in route." << std::endl;
136 int dest_route_index = route_index(dest);
138 if (dest_route_index == -1)
140 glog.is(DEBUG1) &&
glog << group(
"goby::acomms::route")
141 <<
"Destination modem id is not in route." << std::endl;
146 if (dest_route_index < current_route_index)
148 else if (dest_route_index > current_route_index)
153 int next_hop_index = current_route_index + direction;
155 if (next_hop_index < 0 || next_hop_index >= cfg_.route().hop_size())
157 glog.is(DEBUG1) &&
glog << warn << group(
"goby::acomms::route") <<
"Next hop index (" 158 << next_hop_index <<
") is not in route." << std::endl;
162 return cfg_.route().hop(next_hop_index);
165 void goby::acomms::RouteManager::add_subnet_queue(QueueManager* manager)
169 glog.is(DEBUG1) &&
glog << warn << group(
"goby::acomms::route")
170 <<
"Null manager passed to add_subnet_queue. Ignoring." 175 uint32 modem_id = manager->modem_id();
176 uint32 subnet = modem_id & cfg_.subnet_mask();
178 if (subnet_map_.count(subnet))
179 glog.is(DEBUG1) &&
glog << warn << group(
"goby::acomms::route") <<
"Subnet " << subnet
180 <<
" already mapped. Replacing." << std::endl;
182 subnet_map_[subnet] = manager;
184 glog.is(DEBUG1) &&
glog << group(
"goby::acomms::route") <<
"Adding subnet (hex: " << std::hex
185 << subnet << std::dec <<
")" << std::endl;
google::protobuf::uint32 uint32
an unsigned 32 bit integer
common::FlexOstream glog
Access the Goby logger through this object.