public OfpFlowStats(Stream stream)
        {
            BeBinaryReader br = new BeBinaryReader(stream, Encoding.ASCII, true);

            br.Parse(out Length);
            br.Parse(out TableId);
            br.ReadBytes(1);
            Match = new OfpMatch(stream);
            br.Parse(out DurationSec);
            br.Parse(out DurationNsec);
            br.Parse(out Priority);
            br.Parse(out IdleTimeout);
            br.Parse(out HardTimeout);
            br.ReadBytes(6);
            br.Parse(out Cookie);
            br.Parse(out PacketCount);
            br.Parse(out ByteCount);

            IOfpAction action = OfpActionHeader.ParseAction(stream);

            while (action != null)
            {
                Actions[action.Header.Type] = action;
                action = OfpActionHeader.ParseAction(stream);
            }
        }
        public OfpPacketOut(Stream stream, OfpHeader header = null)
        {
            BeBinaryReader br = new BeBinaryReader(stream, Encoding.ASCII, true);

            Header = header ?? new OfpHeader(stream);
            br.Parse(out BufferId);
            br.Parse(out InPort);
            br.Parse(out ActionsLen);

            int length = ActionsLen;

            while (length >= 8)
            {
                var action = OfpActionHeader.ParseAction(stream);
                Actions[action.Header.Type] = action;
                length -= action.Header.Len;
            }

            if (BufferId == uint.MaxValue) //-1
            {
                length = Header.Length - (int)Size - ActionsLen;
                if (length > 0)
                {
                    br.Parse(out Data, length);
                }
            }
        }
        public OfpFlowMod(Stream stream, OfpHeader header = null)
        {
            BeBinaryReader br = new BeBinaryReader(stream, Encoding.ASCII, true);

            Header = header ?? new OfpHeader(stream);
            //var pos = stream.Position;
            Match = new OfpMatch(stream);
            //pos = stream.Position;
            br.Parse(out Cookie);
            br.Parse(out Command);
            br.Parse(out IdleTimeout);
            br.Parse(out HardTimeout);
            br.Parse(out Priority);
            br.Parse(out BufferId);
            br.Parse(out OutPort); //FIXED:
            br.Parse(out Flags);
            //pos = stream.Position;
            IOfpAction action = OfpActionHeader.ParseAction(stream);

            while (action != null)
            {
                Actions[action.Header.Type] = action;
                action = OfpActionHeader.ParseAction(stream);
            }
        }
Beispiel #4
0
        public OfpActionNwAddr(Stream stream)
        {
            BeBinaryReader br = new BeBinaryReader(stream, Encoding.ASCII, true);

            Header = new OfpActionHeader(stream);
            br.Parse(out NwAddr);
        }
Beispiel #5
0
        public OfpActionVendorHeader(Stream stream)
        {
            BeBinaryReader br = new BeBinaryReader(stream, Encoding.ASCII, true);

            Header = new OfpActionHeader(stream);
            br.Parse(out Vendor);
            br.Parse(out Content, Header.Len);
        }
Beispiel #6
0
        public OfpActionTpPort(Stream stream)
        {
            BeBinaryReader br = new BeBinaryReader(stream, Encoding.ASCII, true);

            Header = new OfpActionHeader(stream);
            br.Parse(out TpPort);
            br.ReadBytes(2); //PAD 2
        }
Beispiel #7
0
        public OfpActionNwTos(Stream stream)
        {
            BeBinaryReader br = new BeBinaryReader(stream, Encoding.ASCII, true);

            Header = new OfpActionHeader(stream);
            br.Parse(out NwTos);
            br.ReadBytes(3);
        }
Beispiel #8
0
        public OfpActionDlAddr(Stream stream)
        {
            BeBinaryReader br = new BeBinaryReader(stream, Encoding.ASCII, true);

            Header = new OfpActionHeader(stream);
            br.Parse(out DlAddr, OFP_MAX_ETH_ALEN);
            br.ReadBytes(6);
        }
Beispiel #9
0
        public OfpActionOutput(Stream stream)
        {
            BeBinaryReader br = new BeBinaryReader(stream, Encoding.ASCII, true);

            Header = new OfpActionHeader(stream);
            br.Parse(out Port);
            br.Parse(out MaxLen);
        }
Beispiel #10
0
        public OfpActionEnqueue(Stream stream)
        {
            BeBinaryReader br = new BeBinaryReader(stream, Encoding.ASCII, true);

            Header = new OfpActionHeader(stream);
            br.Parse(out Port);
            br.ReadBytes(6); //PAD 6
            br.Parse(out QueueId);
        }
Beispiel #11
0
        /// <summary>
        /// 通过头解析一个动作
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        public static IOfpAction ParseAction(Stream stream)
        {
            if (stream.Length - stream.Position >= 8)
            {
                var             pos    = stream.Position;
                OfpActionHeader header = new OfpActionHeader(stream);
                stream.Seek(pos, SeekOrigin.Begin);
                switch (header.Type)
                {
                case OfpActionType.OFPAT_OUTPUT:
                    return(new OfpActionOutput(stream));

                case OfpActionType.OFPAT_SET_VLAN_VID:
                    return(new OfpActionVlanVid(stream));

                case OfpActionType.OFPAT_SET_VLAN_PCP:
                    return(new OfpActionVlanPcp(stream));

                case OfpActionType.OFPAT_STRIP_VLAN:
                    return(new OfpActionStripVlan(stream));

                case OfpActionType.OFPAT_SET_DL_SRC:
                    return(new OfpActionDlAddr(stream));

                case OfpActionType.OFPAT_SET_DL_DST:
                    return(new OfpActionDlAddr(stream));

                case OfpActionType.OFPAT_SET_NW_SRC:
                    return(new OfpActionNwAddr(stream));

                case OfpActionType.OFPAT_SET_NW_DST:
                    return(new OfpActionNwAddr(stream));

                case OfpActionType.OFPAT_SET_NW_TOS:
                    return(new OfpActionNwTos(stream));

                case OfpActionType.OFPAT_SET_TP_SRC:
                    return(new OfpActionTpPort(stream));

                case OfpActionType.OFPAT_SET_TP_DST:
                    return(new OfpActionTpPort(stream));

                case OfpActionType.OFPAT_ENQUEUE:
                    return(new OfpActionEnqueue(stream));

                case OfpActionType.OFPAT_VENDOR:
                    return(new OfpActionVendorHeader(stream));

                default:
                    return(null);
                    //throw new FormatException("Can not parse header");
                }
            }
            return(null);
        }
Beispiel #12
0
 public OfpActionStripVlan(Stream stream)
 {
     Header = new OfpActionHeader(stream, 4);
 }