Пример #1
0
        public FlowKey GetKey(Packet packet)
        {
            FlowKey GetUdpFlowKey(UdpPacket udp)
            {
                return(FlowKey.Create((byte)IPProtocolType.UDP,
                                      (udp.ParentPacket as IPPacket).SourceAddress.GetAddressBytes(),
                                      udp.SourcePort,
                                      (udp.ParentPacket as IPPacket).DestinationAddress.GetAddressBytes(),
                                      udp.DestinationPort));
            }

            FlowKey GetTcpFlowKey(TcpPacket tcp)
            {
                return(FlowKey.Create(
                           (byte)IPProtocolType.TCP,
                           (tcp.ParentPacket as IPPacket).SourceAddress.GetAddressBytes(),
                           tcp.SourcePort,
                           (tcp.ParentPacket as IPPacket).DestinationAddress.GetAddressBytes(),
                           tcp.DestinationPort));
            }

            FlowKey GetIpFlowKey(IPPacket ip)
            {
                return(FlowKey.Create(
                           (byte)(ip.Version == IPVersion.IPv4 ? IPProtocolType.IP : IPProtocolType.IPV6),
                           ip.SourceAddress.GetAddressBytes(), 0,
                           ip.DestinationAddress.GetAddressBytes(), 0
                           ));
            }

            switch ((TransportPacket)packet.Extract(typeof(TransportPacket)))
            {
            case UdpPacket udp: return(GetUdpFlowKey(udp));

            case TcpPacket tcp: return(GetTcpFlowKey(tcp));

            default:
                switch ((InternetPacket)packet.Extract(typeof(InternetPacket)))
                {
                case IPPacket ip: return(GetIpFlowKey(ip));

                default: return(FlowKey.Create((byte)IPProtocolType.NONE,
                                               IPAddress.None.GetAddressBytes(), 0, IPAddress.None.GetAddressBytes(), 0));
                }
            }
        }
Пример #2
0
        public void FlowCachePut()
        {
            var flows = CacheFactory.GetOrCreateFlowCache(m_igniteFixture.Server.Ignite, "flows");

            flows.Put(FlowKey.Create(ProtocolType.Tcp, IPAddress.Parse("192.168.1.1"), 35346, IPAddress.Parse("147.229.11.100"), 80),
                      new FlowData
            {
                Protocol           = "TCP",
                SourceAddress      = "192.168.1.1",
                SourcePort         = 35346,
                DestinationAddress = "147.229.11.100",
                DestinationPort    = 80,
                FirstSeen          = 123456789,
                LastSeen           = 123456798,
                Octets             = 88888,
                Packets            = 11,
                ServiceName        = "http-www"
            }
                      );
        }
Пример #3
0
 public void FlowCacheGet()
 {
     var flows    = CacheFactory.GetOrCreateFlowCache(m_igniteFixture.Server.Ignite, "flows");
     var flowData = flows.Get(FlowKey.Create(ProtocolType.Tcp, IPAddress.Parse("192.168.1.1"), 35346, IPAddress.Parse("147.229.11.100"), 80));
 }