예제 #1
0
        /// <summary>
        /// 转发常规数据包
        /// </summary>
        /// <param name="packetInfo"></param>
        /// <returns></returns>
        public static void TranNormalPacket(PacketInfo packetInfo)
        {
            byte[]       packetByte   = packetInfo.GetPacketByte();
            PacketEntity packetEntity = (PacketEntity)Util.BytesToObject(packetByte);
            string       srcIP        = packetEntity.GetHead().strSrcIP;
            string       desIP        = packetEntity.GetHead().strDesIP;

            Const.EN_RET_CODE retVal = Const.EN_RET_CODE.EN_RET_INIT;
            int tranPort             = Const.INVALID_NUM;

            //流表中存在转发选项,直接转发
            if (FlowTable.GetInstance().TryGetItem(desIP, out tranPort))
            {
                retVal = Transmitter.SendViaPhyPort(tranPort, packetByte);
                if (Const.EN_RET_CODE.EN_RET_SUCC != retVal)
                {
                    Util.Log(Util.EN_LOG_LEVEL.EN_LOG_INFO, "数据包转发失败");
                }
            }
            //流表中不存在转发选项,将数据包暂存缓冲区,上报控制器
            else
            {
                Program.BufferQueue.Enqueue(packetInfo);
                PacketHead   head     = new PacketHead(srcIP, desIP, PacketHead.EN_PACKET_TYPE.EN_PACKET_IN);
                PacketEntity packetIn = new PacketEntity(head, "");
                retVal = Transmitter.SendViaPhyPort(0, Util.ObjectToBytes(packetIn));
                if (retVal != Const.EN_RET_CODE.EN_RET_SUCC)
                {
                    Util.Log(Util.EN_LOG_LEVEL.EN_LOG_INFO, "packet_in发送失败");
                }
            }
        }
예제 #2
0
 /// <summary>
 /// 获取单例
 /// </summary>
 /// <returns></returns>
 public static FlowTable GetInstance()
 {
     if (null == instance)
     {
         lock (objLock)
         {
             if (null == instance)
             {
                 instance = new FlowTable();
             }
         }
     }
     return(instance);
 }
예제 #3
0
        /// <summary>
        /// 处理控制器下发的Pakcet_Out消息,监听子线程调用
        /// </summary>
        /// <param name="packetInfo"></param>
        public static void DealPacketOut(PacketInfo packetInfo)
        {
            Console.WriteLine("packet_out");
            byte[]       buffer = packetInfo.GetPacketByte();
            PacketEntity packet = (PacketEntity)Util.BytesToObject(buffer);

            byte[] FlowBuffer = packet.GetByteContent();
            Dictionary <string, int> dictionary = (Dictionary <string, int>)Util.BytesToObject(FlowBuffer);

            for (int i = 0; i < dictionary.Count; i++)
            {
                //Console.WriteLine(dictionary.ElementAt(i).Key + "  " + dictionary.ElementAt(i).Value);
                FlowTableItem fItem = new FlowTableItem(dictionary.ElementAt(i).Key, dictionary.ElementAt(i).Value);
                FlowTable.GetInstance().AddItem(fItem);
            }
            FlowTable.PrintItems();
        }