Example #1
0
        /// <summary>
        /// Called by a connection when it has received an intact and complete message in wire-format.
        /// Parses the supplied byte-array to generate a typed message for processing.
        /// On return from this routine the connection is free to overwrite the buffer contents.
        /// /// </summary>
        /// <param name="conn">Connection (think TCP to specific network agent) on which message arrived.</param>
        /// <param name="buff">Buffer encoding the message.</param>
        /// <param name="offset">Offset to start of message in the supplied buffer.</param>
        /// <param name="length">Length of message encoding in supplied buffer</param>
        public void ReceiveMessage(Connection conn, MessageTypes messageType, byte[] buff, int offset, int length)
        {
            switch (messageType)
            {
                case MessageTypes.MessageTypeRegister:
                    {
                        MessageRegister msgRegister = MessageRegister.CreateFromNetBytes(buff, offset);
                        TenantId = msgRegister.TenantId;
                        client.CallbackMessageRegister(conn, msgRegister.TenantId, msgRegister.AlertVec);
                        MessageAck ack = new MessageAck(msgRegister.SeqNo,
                                                        MessageTypes.MessageTypeRegisterAck,
                                                        (uint)OktoResultCodes.OKTO_RESULT_SUCCESS);
                        SendSynchronous(conn, ack.Serialize);
                        conn.BeginReceive();
                        break;
                    }

                case MessageTypes.MessageTypeIoFlowCreate:
                    {
                        MessageIoFlowCreate msgFlowc = MessageIoFlowCreate.CreateFromNetBytes(buff, offset);
                        lock (LockLocal)
                        {
                            foreach (IoFlowMessageParams flowc in msgFlowc.ListParams)
                            {
                                Console.WriteLine("Agent MessageIoFlowCreate({0},{1})", flowc.FlowId, flowc.ParameterString);
                                if (DictFlowCreateParams.ContainsKey(flowc.FlowId))
                                    throw new ArgumentOutOfRangeException(string.Format("Agent flowc dup FlowId {0}", flowc.FlowId));
                                DictFlowCreateParams.Add(flowc.FlowId, flowc);
                            }
                        }
                        MessageAck ack = new MessageAck(msgFlowc.SeqNo,
                                                        MessageTypes.MessageTypeIoFlowCreateAck,
                                                        (uint)OktoResultCodes.OKTO_RESULT_SUCCESS);
                        SendSynchronous(conn, ack.Serialize);
                        conn.BeginReceive();
                        break;
                    }

                case MessageTypes.MessageTypeRapFsCreate:
                    {
                        MessageRapFsCreate msgRapc = MessageRapFsCreate.CreateFromNetBytes(buff, offset);

                        lock (LockLocal)
                        {
                            foreach (MsgRapArg rapc in msgRapc.ListMsgRapArg)
                            {
                                Console.WriteLine("Agent MessageRapFsCreate({0},{1},{2})", rapc.FlowId, rapc.stringSid, rapc.ShareOrVolume);
                                if (!DictFlowCreateParams.ContainsKey(rapc.FlowId))
                                    throw new ArgumentOutOfRangeException(string.Format("Agent rapc invalid FlowId {0}", rapc.FlowId));
                                if (DictRapCreateParams.ContainsKey(rapc.FlowId))
                                    throw new ArgumentOutOfRangeException(string.Format("Agent rapc dup FlowId {0}", rapc.FlowId));
                                if (!DictFlowCreateParams.ContainsKey(rapc.FlowId))
                                    throw new ArgumentOutOfRangeException(string.Format("Agent rapc unmatched FlowId {0}", rapc.FlowId));
                                DictRapCreateParams.Add(rapc.FlowId, rapc);
                            }
                        }
                        //
                        // Params look reasonable and FlowCreate and RapCreate match up.
                        // Now we can invite the client to create its IoFlows.
                        //
                        OktoResultCodes result = client.CallbackIoFlowCreate(DictFlowCreateParams, DictRapCreateParams);

                        MessageAck ack = new MessageAck(msgRapc.SeqNo,
                                                        MessageTypes.MessageTypeRapFsCreateAck,
                                                        (uint)result);
                        SendSynchronous(conn, ack.Serialize);
                        conn.BeginReceive();
                        break;
                    }

                case MessageTypes.MessageTypeStatsZero:
                    {
                        MessageStatsZero msgZero = MessageStatsZero.CreateFromNetBytes(buff, offset);
                        OktoResultCodes result = client.CallbackMessageStatsZero();
                        MessageAck ack = new MessageAck(msgZero.SeqNo,
                                                        MessageTypes.MessageTypeStatsZeroAck,
                                                        (uint)result);
                        SendSynchronous(conn, ack.Serialize);
                        conn.BeginReceive();
                        break;
                    }

                case MessageTypes.MessageTypeIoFlowUpdate:
                    {
                        MessageIoFlowUpdate msgFlowc = MessageIoFlowUpdate.CreateFromNetBytes(buff, offset);
                        lock (LockLocal)
                        {
                            foreach (IoFlowMessageParams flowu in msgFlowc.ListParams)
                                if (!DictFlowCreateParams.ContainsKey(flowu.FlowId))
                                    throw new ArgumentOutOfRangeException(string.Format("Agent flowu invalid FlowId {0}", flowu.FlowId));
                        }
                        OktoResultCodes result = client.CallbackMessageIoFlowUpdate(msgFlowc.ListParams);
                        MessageAck ack = new MessageAck(msgFlowc.SeqNo,
                                                        MessageTypes.MessageTypeIoFlowUpdateAck,
                                                        (uint)result);
                        SendSynchronous(conn, ack.Serialize);
                        conn.BeginReceive();
                        break;
                    }

                case MessageTypes.MessageTypeTenantDelete:
                    {
                        MessageTenantDelete msgTend = MessageTenantDelete.CreateFromNetBytes(buff, offset);
                        OktoResultCodes result = client.CallbackMessageTenantDelete();
                        MessageAck ack = new MessageAck(msgTend.SeqNo,
                                                        MessageTypes.MessageTypeTenantDeleteAck,
                                                        (uint)result);
                        SendSynchronous(conn, ack.Serialize);
                        conn.BeginReceive();
                        break;
                    }

                case MessageTypes.MessageTypeIoFlowStatsQuery:
                    {
                        MessageIoFlowStatsQuery msgStatsQ = MessageIoFlowStatsQuery.CreateFromNetBytes(buff, offset);
                        List<IoFlowMessageParams> listStats = client.CallbackMessageIoFlowStatsQuery();
                        lock (LockLocal)
                        {
                            foreach (IoFlowMessageParams stats in listStats)
                                if (!DictFlowCreateParams.ContainsKey(stats.FlowId))
                                    throw new ArgumentOutOfRangeException(string.Format("Stats reply invalid FlowId {0}", stats.FlowId));
                        }
                        MessageIoFlowStatsReply msgStatsReply = new MessageIoFlowStatsReply(msgStatsQ.SeqNo, listStats, TenantId);
                        SendSynchronous(conn, msgStatsReply.Serialize);
                        conn.BeginReceive();
                        break;
                    }

                case MessageTypes.MessageTypeNameToStringSidBatchQuery:
                    {
                        MessageNameToStringSidBatchQuery msgSidBatchQuery =
                            MessageNameToStringSidBatchQuery.CreateFromNetBytes(buff, offset);
                        Dictionary<string, string> DictVmNameToSid = new Dictionary<string, string>();
                        System.Security.Principal.SecurityIdentifier sid = null;
                        foreach (string vmName in msgSidBatchQuery.ListVmNames)
                        {
                            //XXXET: following two lines are for account names of type europe\
                            sid = VmSID.GetVMnameSid(vmName);
                            if (sid == null)
                            {
                                try
                                {
                                    NTAccount ntaccount = new NTAccount(vmName);
                                    sid = (SecurityIdentifier)ntaccount.Translate(typeof(SecurityIdentifier));
                                }
                                catch (Exception e)
                                {
                                    Debug.Assert(0 == 1, e.Message);
                                }
                            }

                            Console.WriteLine("MessageTypeNameToStringSidBatchQuery: {0} sid {1}", vmName, sid.ToString());
                            DictVmNameToSid.Add(vmName, sid.ToString());
                        }
                        MessageVmNameToStringSidBatchReply msgSidReply =
                            new MessageVmNameToStringSidBatchReply(msgSidBatchQuery.SeqNo,
                                                                   (uint)OktoResultCodes.OKTO_RESULT_SUCCESS,
                                                                   DictVmNameToSid);
                        SendSynchronous(conn, msgSidReply.Serialize);
                        conn.BeginReceive();
                        break;
                    }

                default:
                    {
                        string msg = string.Format("ReceiveMessage: unexpected message type {0}", messageType);
                        throw new ApplicationException(msg);
                    }
            } // switch
        }
Example #2
0
 public static MessageAck CreateFromNetBytes(byte[] buffer, int offset)
 {
     MessageAck msg = new MessageAck();
     msg.Length = (uint)Utils.Int32FromNetBytes(buffer, offset); offset += 4;
     msg.SeqNo = (uint)Utils.Int32FromNetBytes(buffer, offset); offset += 4;
     msg.MessageType = buffer[offset++];
     msg.Result = (uint)Utils.Int32FromNetBytes(buffer, offset); offset += 4;
     msg.SubType = buffer[offset++];
     return msg;
 }