GL::push_matrix();
GL::translate(-500, 360, 0);
unsigned n = 0;
- for(map<unsigned, Port *>::iterator i=ports.begin(); (i!=ports.end() && n<50); ++i, ++n)
+ for(map<unsigned, Port *>::iterator i=ports.begin(); (i!=ports.end() && n<50); ++i)
{
- i->second->render();
- GL::translate(0, -12, 0);
+ float act = i->second->get_activity();
+ if((i->second->is_registered() && act>1) || act>200)
+ {
+ i->second->render();
+ GL::translate(0, -12, 0);
+ ++n;
+ }
}
GL::pop_matrix();
return *host;
}
-const Port &NetVis::get_port(unsigned number)
+Port &NetVis::get_port(unsigned number)
{
map<unsigned, Port *>::iterator i = ports.find(number);
if(i!=ports.end())
const iphdr *ip = reinterpret_cast<const iphdr *>(eth+1);
unsigned size = ntohs(ip->tot_len);
- unsigned port = 0;
+
+ Port *sport = 0;
+ Port *dport = 0;
if(ip->protocol==IPPROTO_TCP)
{
const tcphdr *tcp = reinterpret_cast<const tcphdr *>(ip+1);
- port = min(ntohs(tcp->source), ntohs(tcp->dest));
+ sport = &self->get_port(ntohs(tcp->source));
+ dport = &self->get_port(ntohs(tcp->dest));
}
else if(ip->protocol==IPPROTO_UDP)
{
const udphdr *udp = reinterpret_cast<const udphdr *>(ip+1);
- port = min(ntohs(udp->source), ntohs(udp->dest));
+ sport = &self->get_port(ntohs(udp->source));
+ dport = &self->get_port(ntohs(udp->dest));
}
+
+ Port *port = 0;
+ if(sport && dport)
+ {
+ if(sport->is_registered()!=dport->is_registered())
+ {
+ if(sport->is_registered())
+ port = sport;
+ else
+ port = dport;
+ }
+ else if(sport->get_number()<dport->get_number())
+ port = sport;
+ else
+ port = dport;
+ }
+ else
+ port = &self->get_port(0);
+
Host &shost = self->get_host(ntohl(ip->saddr));
Host *dhost = 0;
if((ntohl(ip->daddr)&0xFF)!=0xFF)
float throttle = shost.send_packet();
if(throttle<1)
{
- self->packets.push_back(new Packet(shost, dhost, self->get_port(port).get_color(), size));
+ self->packets.push_back(new Packet(shost, dhost, port->get_color(), size));
self->packets.back()->tick(-throttle*Msp::Time::sec);
}
if(dhost)
dhost->add_activity(size);
+ if(sport)
+ sport->add_activity(size);
+ if(dport)
+ dport->add_activity(size);
+
if((ntohl(ip->saddr)&self->localnet_mask)==self->localnet)
self->history->activity(0, size);
else if((ntohl(ip->daddr)&self->localnet_mask)==self->localnet)
bld.end();
}
+void Port::add_activity(unsigned bytes)
+{
+ activity.add_bytes(bytes);
+}
+
+void Port::tick(const Time::TimeDelta &dt)
+{
+ activity.tick(dt);
+}
+
void Port::render() const
{
GL::PushMatrix push_;
mesh.draw();
+ {
+ GL::Immediate imm((GL::COLOR4_UBYTE, GL::VERTEX2));
+ imm.begin(GL::QUADS);
+ imm.color(color.r, color.g, color.b, color.a);
+ unsigned x = static_cast<unsigned>(activity.get_average()/4096);
+ imm.vertex(14, 0);
+ imm.vertex(14+x, 0);
+ imm.vertex(14+x, 10);
+ imm.vertex(14, 10);
+ imm.end();
+ }
GL::translate(16, 1, 0);
GL::scale_uniform(10);
- GL::Immediate imm((GL::COLOR4_UBYTE, GL::TEXCOORD2, GL::VERTEX2));
- netvis.get_font().draw_string(name, imm);
+ {
+ GL::Immediate imm((GL::COLOR4_UBYTE, GL::TEXCOORD2, GL::VERTEX2));
+ netvis.get_font().draw_string(name, imm);
+ }
GL::Texture::unbind();
}