コード例 #1
0
        private void Initialize(MemoryStream ms, OfpHeader header)
        {
            if (!_versionChecked)
            {
                _version        = header.Version;
                _versionChecked = true;
                var reply = new OfpSwitchFeaturesRequest();
                _log.Debug("Request for features");
                //Console.WriteLine("Request for features");
                Write(reply.ToByteArray());
            }
            else if (header.Type == OfpType.OFPT_FEATURES_REPLY)
            {
                OfpSwitchFeatures features = new OfpSwitchFeatures(ms, header);
                _mac = features.DatapathId.GetPhysicalAddress();
                _log.Info($"A switch connected - MAC={_mac}");
                //Console.WriteLine($"A switch connected - MAC={_mac}");
                foreach (var ofpPhyPort in features.Ports)
                {
                    //Console.WriteLine($"\tPortNum={ofpPhyPort.PortNo} \tPortName={ofpPhyPort.Name} \tPortState={ofpPhyPort.State.ToString()}");
                }
                SwitchFeatures  = features;
                _featureChecked = true;
                var reply = new OfpSwitchConfig(true);
                reply.Flags       = OfpConfigFlags.OFPC_FRAG_NORMAL;
                reply.MissSendLen = 65535;
                Write(reply.ToByteArray());
                var reply2 = new OfpSwitchConfigRequest();
                Write(reply2.ToByteArray());
            }
            else if (header.Type == OfpType.OFPT_GET_CONFIG_REPLY)
            {
                OfpSwitchConfig config = new OfpSwitchConfig(ms, header);
                _log.Info($"[{_mac}] Config: Flag={config.Flags} MissSendLen={config.MissSendLen}");
                //Console.WriteLine($"[{_mac}] Config: Flag={config.Flags} MissSendLen={config.MissSendLen}");
                _configChecked = true;
                return;
            }
            else if (header.Type == OfpType.OFPT_ECHO_REQUEST)
            {
                OfpEcho echo = new OfpEcho(ms, header);
                _version        = echo.Header.Version;
                _versionChecked = true;
                var reply = new OfpEcho(true);
                reply.Data = echo.Data;
                Write(reply.ToByteArray());
            }
            else if (header.Type == OfpType.OFPT_ERROR)
            {
                OfpErrorMsg error = new OfpErrorMsg(ms, header);
                _log.Info($"[{_mac}] Error: type={error.Type.ToString()} code={error.GetErrorCode()}");
                //Console.WriteLine($"[{_mac}] Error: type={error.Type.ToString()} code={error.GetErrorCode()}");
                return;
            }

            else
            {
                return;
            }
        }
コード例 #2
0
        private void Echo(MemoryStream ms, OfpHeader header)
        {
            OfpEcho echo = new OfpEcho(ms, header);

            if (echo.Header.Type == OfpType.OFPT_ECHO_REQUEST)
            {
                Write(new OfpEcho(true).ToByteArray());
            }
            _controller.PluginSystem.Echo(echo, this);
        }
コード例 #3
0
 /// <summary>
 /// 处理Echo
 /// </summary>
 /// <param name="echo"></param>
 /// <param name="handler"></param>
 /// <returns></returns>
 public virtual bool Echo(OfpEcho echo, IConnection handler)
 {
     foreach (var plugin in Plugins.Values.Where(plugin => plugin.Active))
     {
         try
         {
             bool result = plugin.MessageHandler.Echo(echo, handler);
             if (result)
             {
                 break;
             }
         }
         catch (Exception e)
         {
             Debug.WriteLine(e);
         }
     }
     return(true);
 }
コード例 #4
0
ファイル: MessageHandler.cs プロジェクト: lanicon/FlowNet
 /// <summary>
 /// 处理Echo
 /// </summary>
 /// <param name="echo"></param>
 /// <param name="handler"></param>
 /// <returns></returns>
 public virtual bool Echo(OfpEcho echo, IConnection handler)
 {
     return(false);
 }