Skip to content

Instantly share code, notes, and snippets.

@voidlizard
Created December 10, 2012 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save voidlizard/70a12ec6c01be0cf2832 to your computer and use it in GitHub Desktop.
Save voidlizard/70a12ec6c01be0cf2832 to your computer and use it in GitHub Desktop.
-- Get SCMessage body
{-# INLINE getSCMessageBody #-}
getSCMessageBody :: OFPHeader -> Get (M.TransactionID, M.SCMessage)
getSCMessageBody hdr@(OFPHeader {..}) =
if msgType == ofptPacketIn
then do packetInRecord <- getPacketInRecord len
return (msgTransactionID, M.PacketIn packetInRecord)
else if msgType == ofptEchoRequest
then do bytes <- getWord8s (len - headerSize)
return (msgTransactionID, M.SCEchoRequest bytes)
else if msgType == ofptEchoReply
then do bytes <- getWord8s (len - headerSize)
return (msgTransactionID, M.SCEchoReply bytes)
else if msgType == ofptFeaturesReply
then do switchFeaturesRecord <- getSwitchFeaturesRecord len
return (msgTransactionID, M.Features switchFeaturesRecord)
else if msgType == ofptHello
then return (msgTransactionID, M.SCHello)
else if msgType == ofptPortStatus
then do body <- getPortStatus
return (msgTransactionID, M.PortStatus body)
else if msgType == ofptError
then do body <- getSwitchError len
return (msgTransactionID, M.Error body)
else if msgType == ofptFlowRemoved
then do body <- getFlowRemovedRecord
return (msgTransactionID, M.FlowRemoved body)
else if msgType == ofptBarrierReply
then return (msgTransactionID, M.BarrierReply)
else if msgType == ofptStatsReply
then do body <- getStatsReply len
return (msgTransactionID, M.StatsReply body)
else if msgType == ofptQueueGetConfigReply
then do qcReply <- getQueueConfigReply len
return (msgTransactionID, M.QueueConfigReply qcReply)
else error ("Unrecognized message header: " ++ show hdr)
where len = fromIntegral msgLength
@dmalikov
Copy link

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment