private void Error(MemoryStream ms, OfpHeader header) { OfpErrorMsg error = new OfpErrorMsg(ms, header); Debug.WriteLine($"[{_mac}] ERROR:{error.Type} - {error.GetErrorCode()}"); _log.Info($"[{_mac}] ERROR:{error.Type} - {error.GetErrorCode()}"); //Console.WriteLine($"[{_mac}] ERROR:{error.Type} - {error.GetErrorCode()}"); _controller.PluginSystem.Error(error, this); }
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; } }