예제 #1
0
	def test_encodeAndDecode(self):
		""" Test encoding and decoding of a message header """
		msg = MAGIMessage()
		msg.msgid = 1234
		msg.flags = 0x63
		msg.contenttype = MAGIMessage.YAML
		msg.src = "mynode"
		msg.srcdock = "sourcedock"
		msg.hmac = "123456789"
		msg.dstnodes = set(['n1', 'n2'])
		msg.dstgroups = set(['g1', 'g2'])
		msg.dstdocks = set(['d1', 'd2'])
		msg.sequence = 98765
		msg.timestamp = 12347890
		msg.data = None

		codec = DefaultCodec()

		hdr = codec.encode(msg)
		ret, hdrsize = codec.decode(hdr)
		ret.data = None
		
		self.assertEquals(hdrsize, len(hdr))

		for k, v in msg.__dict__.iteritems():
			if k[0] == '_':
				continue
			self.assertEquals(getattr(ret, k), v)
예제 #2
0
    def test_encodeAndDecode(self):
        """ Test encoding and decoding of a message header """
        msg = MAGIMessage()
        msg.msgid = 1234
        msg.flags = 0x63
        msg.contenttype = MAGIMessage.YAML
        msg.src = "mynode"
        msg.srcdock = "sourcedock"
        msg.hmac = "123456789"
        msg.dstnodes = set(['n1', 'n2'])
        msg.dstgroups = set(['g1', 'g2'])
        msg.dstdocks = set(['d1', 'd2'])
        msg.sequence = 98765
        msg.timestamp = 12347890
        msg.data = None

        codec = DefaultCodec()

        hdr = codec.encode(msg)
        ret, hdrsize = codec.decode(hdr)
        ret.data = None

        self.assertEquals(hdrsize, len(hdr))

        for k, v in msg.__dict__.iteritems():
            if k[0] == '_':
                continue
            self.assertEquals(getattr(ret, k), v)
예제 #3
0
	def addMsg(self, msgid):
		self.msgid += 1
		msg = MAGIMessage()
		msg.msgid = self.msgid
		msg.contenttype = MAGIMessage.NONE
		msg.src = "mynode"
		msg.srcdock = "sourcedock"
		msg.dstgroups = ['g1']
		msg.data = None
		self.mct.processPacket('192.168.1.1', 18808, MCTHeader.PktData(msgid, 1, 1).encode() + self.msgcodec.encode(msg))
예제 #4
0
	def addBigMessage(self, mid, count, skip):
		msg = MAGIMessage()
		msg.msgid = 12345
		msg.contenttype = MAGIMessage.NONE
		msg.src = "mynode"
		msg.srcdock = "sourcedock"
		msg.dstgroups = ['g1']
		msg.data = "X" * (((TXMessageTracker.SPLITSIZE-4) * count) - len(self.msgcodec.encode(msg)))
		tracker = TXMessageTracker(msg=msg, multicastid=mid, codec=DefaultCodec())
		for ii in range(1,count+1):
			if ii not in skip:
				self.mct.processPacket('192.168.1.1', 18808, tracker.getPart(ii))
	def sendMsg(self):
		self.msgid += 1
		msg = MAGIMessage()
		msg.msgid = self.msgid
		msg.contenttype = MAGIMessage.NONE
		msg.src = "clientnode"
		msg.srcdock = "clientdock"
		msg.dstgroups = ['multicastgroup']
		msg.data = "testing"
		msg._routed = [self.conn.fileno()]
		self.messenger.thread.sendDirect(msg)
		while self.messenger.thread.pollMap[self.conn.fileno()].outmessages:
			time.sleep(0.2) #waiting for message to be sent
	def sendMsg(self):
		self.msgid += 1
		msg = MAGIMessage()
		msg.msgid = self.msgid
		msg.contenttype = MAGIMessage.NONE
		msg.src = "servernode"
		msg.srcdock = "serverdock"
		msg.dstgroups = ['multicastgroup']
		msg.data = "success"
		msg._routed = [self.conn.fileno()]
		self.messenger.thread.sendDirect(msg)
		while self.messenger.thread.pollMap[self.conn.fileno()].outmessages:
			time.sleep(0.2) #waiting for message to be sent
예제 #7
0
 def addMsg(self, msgid):
     self.msgid += 1
     msg = MAGIMessage()
     msg.msgid = self.msgid
     msg.contenttype = MAGIMessage.NONE
     msg.src = "mynode"
     msg.srcdock = "sourcedock"
     msg.dstgroups = ['g1']
     msg.data = None
     self.mct.processPacket(
         '192.168.1.1', 18808,
         MCTHeader.PktData(msgid, 1, 1).encode() +
         self.msgcodec.encode(msg))
예제 #8
0
	def newMsg(self):
		msg = MAGIMessage()
		msg.msgid = 1234
		msg.flags = 0x0
		msg.contenttype = MAGIMessage.YAML
		msg.src = "mynode"
		msg.srcdock = "sourcedock"
		msg.hmac = "123456789"
		msg.dstnodes = ['n1', 'n2']
		msg.dstgroups = ['g1', 'g2']
		msg.dstdocks = ['d1', 'd2']
		msg.sequence = 98765
		msg.timestamp = 12347890
		msg.data = "helloworld"
		return msg
예제 #9
0
	def newMsg(self):
		msg = MAGIMessage()
		msg.msgid = 1234
		msg.flags = 0x63
		msg.contenttype = MAGIMessage.YAML
		msg.src = "mynode"
		msg.srcdock = "sourcedock"
		msg.hmac = "123456789"
		msg.dstnodes = set(['n1', 'n2'])
		msg.dstgroups = set(['g1', 'g2'])
		msg.dstdocks = set(['d1', 'd2'])
		msg.sequence = 98765
		msg.timestamp = 12347890
		msg.data = "helloworld"
		return msg
예제 #10
0
 def addBigMessage(self, mid, count, skip):
     msg = MAGIMessage()
     msg.msgid = 12345
     msg.contenttype = MAGIMessage.NONE
     msg.src = "mynode"
     msg.srcdock = "sourcedock"
     msg.dstgroups = ['g1']
     msg.data = "X" * (((TXMessageTracker.SPLITSIZE - 4) * count) -
                       len(self.msgcodec.encode(msg)))
     tracker = TXMessageTracker(msg=msg,
                                multicastid=mid,
                                codec=DefaultCodec())
     for ii in range(1, count + 1):
         if ii not in skip:
             self.mct.processPacket('192.168.1.1', 18808,
                                    tracker.getPart(ii))