Exemplo n.º 1
0
        //private void Test()
        //{
        //    var b = GenerateLldpPacket(EthernetAddress.ETHER_ANY, 3389, 12345);
        //}

        public bool SendLldpPacket(IConnection connection, OfpPhyPort port)
        {
            if (OfpPhyPort.IsReservedPort(port.PortNo))
            {
                return(false);
            }
            _controller.LogDebug($"[{connection.Mac}] Sending LLDP to Port:{port.PortNo} (PortMAC:{port.HwAddr.ToPhysicalAddress()})");
            OfpPacketOut packetOut = new OfpPacketOut
            {
                Data =
                    GenerateLldpPacket(port.HwAddr.ToPhysicalAddress(), port.PortNo,
                                       connection.SwitchFeatures.DatapathId)
            };

            packetOut.Actions.Add(OfpActionType.OFPAT_OUTPUT, new OfpActionOutput()
            {
                Port = port.PortNo
            });
            connection.Write(packetOut.ToByteArray());
            return(true);
        }
Exemplo n.º 2
0
        public void TestOfpPhyPort()
        {
            OfpPhyPort dst = new OfpPhyPort();
            OfpPhyPort src = new OfpPhyPort()
            {
                Advertised = OfpPortFeatures.OFPPF_100MB_HD, State = OfpPortState.OFPPS_STP_LISTEN, Curr = OfpPortFeatures.OFPPF_100MB_FD, Peer = OfpPortFeatures.OFPPF_FIBER, Name = "TestPort", HwAddr = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 }, Supported = OfpPortFeatures.OFPPF_1GB_HD, PortNo = (ushort)OfpPort.OFPP_FLOOD, Config = OfpPortConfig.OFPPC_NO_FLOOD
            };

            using (MemoryStream ms = new MemoryStream(src.ToByteArray()))
            {
                dst = new OfpPhyPort(ms);
            }
            Assert.AreEqual(src.PortNo, dst.PortNo);
            Assert.AreEqual(src.Advertised, dst.Advertised);
            Assert.AreEqual(src.State, dst.State);
            Assert.AreEqual(src.Config, dst.Config);
            Assert.AreEqual(src.Curr, dst.Curr);
            Assert.AreEqual(src.HwAddr.ToPhysicalAddress(), dst.HwAddr.ToPhysicalAddress());
            Assert.AreEqual(src.Name, dst.Name);
            Assert.AreEqual(src.Peer, dst.Peer);
            Assert.AreEqual(src.Supported, dst.Supported);
        }