private void InstallFlow(IConnection connection) { _controller.Topo.AddSwitch(connection.SwitchFeatures, connection); _controller.LogDebug($"[{connection.Mac}] Installing Discovery Flow"); OfpMatch match = new OfpMatch { Wildcards = new OfpWildcards() { Wildcards = OfpFlowWildcards.OFPFW_DL_TYPE | OfpFlowWildcards.OFPFW_DL_DST }, DlType = (ushort)EthernetPacketType.LLDP, DlDst = EthernetAddress.NDP_MULTICAST.GetAddressBytes() }; OfpFlowMod flow = new OfpFlowMod { Priority = _flowPriority, Match = match }; flow.Actions[OfpActionType.OFPAT_OUTPUT] = new OfpActionOutput() { Port = (ushort)OfpPort.OFPP_CONTROLLER }; connection.Write(flow.ToByteArray()); //Console.WriteLine($"[{connection.Mac}]Sending LLDP"); foreach (var port in connection.SwitchFeatures.Ports) { _handler.SendLldpPacket(connection, port); } }
private void SendFlowMod(IConnection connection, Link link, PhysicalAddress src, PhysicalAddress dst, ushort priority = _flowPriority) { OfpMatch match = new OfpMatch { //Wildcards = new OfpWildcards() { Wildcards = 0 }, Wildcards = new OfpWildcards() { Wildcards = ~(OfpFlowWildcards.OFPFW_DL_DST | OfpFlowWildcards.OFPFW_DL_SRC), NwDstMask = 63, NwSrcMask = 63 }, DlSrc = src.GetAddressBytes(), DlDst = dst.GetAddressBytes() }; OfpFlowMod flow = new OfpFlowMod { Priority = priority, Match = match }; flow.Actions[OfpActionType.OFPAT_OUTPUT] = new OfpActionOutput() { Port = link.SrcPort }; _controller.LogDebug($"[{connection.Mac}]FlowMod from [{src}] to [{dst}]"); connection.Write(flow.ToByteArray()); }
public void TestOfpFlowMod() { OfpFlowMod dst; //A flow entry to redirect all packets which dst-port is 3306(mysql) to dst-port 1433(sqlserver) OfpFlowMod src = new OfpFlowMod() { Command = OfpFlowModCommand.OFPFC_ADD, Match = new OfpMatch() { Wildcards = new OfpWildcards() { Wildcards = ~OfpFlowWildcards.OFPFW_TP_SRC }, TpDst = 3306, }, Actions = new ActionList() { { OfpActionType.OFPAT_SET_TP_DST, new OfpActionTpPort(true) { TpPort = 1433 } }, { OfpActionType.OFPAT_OUTPUT, new OfpActionOutput() { Port = (ushort)OfpPort.OFPP_ALL } } } }; using (MemoryStream ms = new MemoryStream(src.ToByteArray())) { dst = new OfpFlowMod(ms); } Assert.AreEqual(src.Match.Wildcards, dst.Match.Wildcards); Assert.AreEqual(src.Match.TpDst, dst.Match.TpDst); Assert.IsTrue(((OfpActionOutput)dst.Actions[OfpActionType.OFPAT_OUTPUT]).Port == (ushort)OfpPort.OFPP_ALL); Assert.IsTrue(((OfpActionTpPort)dst.Actions[OfpActionType.OFPAT_SET_TP_DST]).TpPort == 1433); }
private void SendFlowMod(Topology.Switch sw, Link link, IPAddress src, IPAddress dst, ushort priority = _flowPriority) { OfpMatch match = new OfpMatch { Wildcards = new OfpWildcards() { NwDstMask = 0, NwSrcMask = 0 }, NwSrc = (uint)src.Address, NwDst = (uint)dst.Address, }; OfpFlowMod flow = new OfpFlowMod { Priority = priority, Match = match }; flow.Actions[OfpActionType.OFPAT_OUTPUT] = new OfpActionOutput() { Port = link.SrcPort }; _controller.LogDebug($"[{sw.MacAddress}]FlowMod from [{src}] to [{dst}]"); sw.Connection.Write(flow.ToByteArray()); }