Пример #1
0
    def __init__(self):
        self.t = Tossim([])
        self.r = self.t.radio()

        #Create a Command Packet
        self.msg = CommandMsg()
        self.pkt = self.t.newPacket()
        self.pkt.setType(self.msg.get_amType())
Пример #2
0
    def __init__(self):
        self.t = Tossim([]) # tiny os simulator
        self.r = self.t.radio() # creates a radio from tiny os simulator

        #Create a Command Packet
        self.msg = CommandMsg()
        self.pkt = self.t.newPacket()
        self.pkt.setType(self.msg.get_amType())
    def __init__(self):
        self.t = Tossim([])
        self.r = self.t.radio()

        #Create a Command Packet
        self.msg = CommandMsg()
        self.pkt = self.t.newPacket()
        self.pkt.setType(self.msg.get_amType())
Пример #4
0
class TestSim:
    moteids = []
    # COMMAND TYPES
    CMD_PING = 0
    CMD_NEIGHBOR_DUMP = 1
    CMD_ROUTE_DUMP = 3

    # CHANNELS - see includes/channels.h
    COMMAND_CHANNEL = "command"
    GENERAL_CHANNEL = "general"

    # Project 1
    NEIGHBOR_CHANNEL = "neighbor"
    FLOODING_CHANNEL = "flooding"

    # Project 2
    ROUTING_CHANNEL = "routing"

    # Project 3
    TRANSPORT_CHANNEL = "transport"

    # Personal Debuggin Channels for some of the additional models implemented.
    HASHMAP_CHANNEL = "hashmap"

    # Initialize Vars
    numMote = 0

    def __init__(self):
        self.t = Tossim([])
        self.r = self.t.radio()

        #Create a Command Packet
        self.msg = CommandMsg()
        self.pkt = self.t.newPacket()
        self.pkt.setType(self.msg.get_amType())

    # Load a topo file and use it.
    def loadTopo(self, topoFile):
        print 'Creating Topo!'
        # Read topology file.
        topoFile = 'topo/' + topoFile
        f = open(topoFile, "r")
        self.numMote = int(f.readline())
        print 'Number of Motes', self.numMote
        for line in f:
            s = line.split()
            if s:
                print " ", s[0], " ", s[1], " ", s[2]
                self.r.add(int(s[0]), int(s[1]), float(s[2]))
                if not int(s[0]) in self.moteids:
                    self.moteids = self.moteids + [int(s[0])]
                if not int(s[1]) in self.moteids:
                    self.moteids = self.moteids + [int(s[1])]

    # Load a noise file and apply it.
    def loadNoise(self, noiseFile):
        if self.numMote == 0:
            print "Create a topo first"
            return

        # Get and Create a Noise Model
        noiseFile = 'noise/' + noiseFile
        noise = open(noiseFile, "r")
        for line in noise:
            str1 = line.strip()
            if str1:
                val = int(str1)
            for i in self.moteids:
                self.t.getNode(i).addNoiseTraceReading(val)

        for i in self.moteids:
            print "Creating noise model for ", i
            self.t.getNode(i).createNoiseModel()

    def bootNode(self, nodeID):
        if self.numMote == 0:
            print "Create a topo first"
            return
        self.t.getNode(nodeID).bootAtTime(1333 * nodeID)

    def bootAll(self):
        i = 0
        for i in self.moteids:
            self.bootNode(i)

    def moteOff(self, nodeID):
        self.t.getNode(nodeID).turnOff()

    def moteOn(self, nodeID):
        self.t.getNode(nodeID).turnOn()

    def run(self, ticks):
        for i in range(ticks):
            self.t.runNextEvent()

    # Rough run time. tickPerSecond does not work.
    def runTime(self, amount):
        self.run(amount * 1000)

    # Generic Command
    def sendCMD(self, ID, dest, payloadStr):
        self.msg.set_dest(dest)
        self.msg.set_id(ID)
        self.msg.setString_payload(payloadStr)

        self.pkt.setData(self.msg.data)
        self.pkt.setDestination(dest)
        self.pkt.deliver(dest, self.t.time() + 5)

    def ping(self, source, dest, msg):
        self.sendCMD(self.CMD_PING, source, "{0}{1}".format(chr(dest), msg))

    def neighborDMP(self, destination):
        self.sendCMD(self.CMD_NEIGHBOR_DUMP, destination, "neighbor command")

    def routeDMP(self, destination):
        self.sendCMD(self.CMD_ROUTE_DUMP, destination, "routing command")

    def addChannel(self, channelName, out=sys.stdout):
        print 'Adding Channel', channelName
        self.t.addChannel(channelName, out)
Пример #5
0
class TestSim:
    # COMMAND TYPES
    CMD_PING = 0
    CMD_NEIGHBOR_DUMP = 1
    CMD_ROUTE_DUMP = 3
    CMD_LINKSTATE_DUMP = 2

    #David added these commands. Their number values are copied from command.h
    CMD_TEST_CLIENT = 4
    CMD_TEST_SERVER = 5
    CMD_KILL = 6
    CMD_MSG = 7
    CMD_CLIENT_APP = 8  #to set up app client
    CMD_SERVER_APP = 10  #to set up the app server
    # Majok
    CMD_LIST_USR = 11  #to set up the app server
    CMD_BROADCAST_MSG = 12  # To used to broadcast a message to all users

    # CHANNELS - see includes/channels.h
    COMMAND_CHANNEL = "command"
    GENERAL_CHANNEL = "general"

    # Project 1
    NEIGHBOR_CHANNEL = "neighbor"
    FLOODING_CHANNEL = "flooding"

    # Project 2
    ROUTING_CHANNEL = "routing"

    # Project 3
    TRANSPORT_CHANNEL = "transport"
    CLEAN_OUTPUT = 'cleanoutput'

    # Personal Debuggin Channels for some of the additional models implemented.
    HASHMAP_CHANNEL = "hashmap"

    FINAL_OUTPUT = "finaloutput"

    # Initialize Vars
    numMote = 0

    def __init__(self):
        self.t = Tossim([])
        self.r = self.t.radio()

        #Create a Command Packet
        self.msg = CommandMsg()
        self.pkt = self.t.newPacket()
        self.pkt.setType(self.msg.get_amType())

    # Load a topo file and use it.
    def loadTopo(self, topoFile):
        print 'Creating Topo!'
        # Read topology file.
        topoFile = 'topo/' + topoFile
        f = open(topoFile, "r")
        self.numMote = int(f.readline())
        print 'Number of Motes', self.numMote
        for line in f:
            s = line.split()
            if s:
                print " ", s[0], " ", s[1], " ", s[2]
                self.r.add(int(s[0]), int(s[1]), float(s[2]))

    # Load a noise file and apply it.
    def loadNoise(self, noiseFile):
        if self.numMote == 0:
            print "Create a topo first"
            return

        # Get and Create a Noise Model
        noiseFile = 'noise/' + noiseFile
        noise = open(noiseFile, "r")
        for line in noise:
            str1 = line.strip()
            if str1:
                val = int(str1)
            for i in range(1, self.numMote + 1):
                self.t.getNode(i).addNoiseTraceReading(val)

        for i in range(1, self.numMote + 1):
            print "Creating noise model for ", i
            self.t.getNode(i).createNoiseModel()

    def bootNode(self, nodeID):
        if self.numMote == 0:
            print "Create a topo first"
            return
        self.t.getNode(nodeID).bootAtTime(1333 * nodeID)

    def bootAll(self):
        i = 0
        for i in range(1, self.numMote + 1):
            self.bootNode(i)

    def moteOff(self, nodeID):
        self.t.getNode(nodeID).turnOff()

    def moteOn(self, nodeID):
        self.t.getNode(nodeID).turnOn()

    def run(self, ticks):
        for i in range(ticks):
            self.t.runNextEvent()

    # Rough run time. tickPerSecond does not work.
    def runTime(self, amount):
        self.run(amount * 1000)

    # Generic Command
    def sendCMD(self, ID, dest, payloadStr):
        self.msg.set_dest(dest)
        self.msg.set_id(ID)
        self.msg.setString_payload(payloadStr)

        self.pkt.setData(self.msg.data)
        self.pkt.setDestination(dest)
        self.pkt.deliver(dest, self.t.time() + 5)

    def ping(self, source, dest, msg):
        self.sendCMD(self.CMD_PING, source, "{0}{1}".format(chr(dest), msg))

    def neighborDMP(self, destination):
        self.sendCMD(self.CMD_NEIGHBOR_DUMP, destination, "neighbor command")

    def routeDMP(self, destination):
        self.sendCMD(self.CMD_ROUTE_DUMP, destination, "routing command")

    def linkStateDMP(self, destination):
        self.sendCMD(self.CMD_LINKSTATE_DUMP, destination, "linkstate command")

    def addChannel(self, channelName, out=sys.stdout):
        print 'Adding Channel', channelName
        self.t.addChannel(channelName, out)

        # David is not actually sure if these next new 3 functions work:

    def cmdTestServer(self, source, port):
        #self.sendCMD (self.CMD_TEST_SERVER, address, port);
        self.sendCMD(self.CMD_TEST_SERVER, source, "{0}".format(chr(port)))
        #Initiates the server at node [address] and binds it to [port]
        #print 'Testing '
        #

    #def cmdTestClient(self, source, dest):
    #	self.sendCMD(self.CMD_TEST_CLIENT, source, "{0}".format(chr(dest)));
    def cmdTestClient(self, source, destination, srcPort, destPort, transfer):
        self.sendCMD(
            self.CMD_TEST_CLIENT,
            source, "{0}{1}{2}{3}".format(chr(destination), chr(srcPort),
                                          chr(destPort), chr(transfer)))

    #	self.sendCMD (self.CMD_TEST_CLIENT, destination, "client command");

    def cmdClientClose(self, source, destination, srcPort, destPort):
        self.sendCMD(
            self.CMD_KILL, source, "{0}{1}{2}".format(chr(destination),
                                                      chr(srcPort),
                                                      chr(destPort)))
        #self.sendCMD (self.CMD_KILL, destination, "close command");

    def cmdSetAppServer(self, source, port):
        #print("{0}".format(chr(port)));
        self.sendCMD(self.CMD_SERVER_APP, source, "{0}".format(chr(port)))

    def cmdSetAppClient(self, source, destination, srcPort, destPort,
                        username):
        self.sendCMD(
            self.CMD_CLIENT_APP,
            source, "{0}{1}{2}{3}".format(chr(destination), chr(srcPort),
                                          chr(destPort), username))
        #print("{0}{1}{2}".format(chr(destination), chr(srcPort), chr(destPort)));
        #self.sendCMD(self.CMD_CLIENT_APP, source, "{0}{1}{2}".format(chr(destination), chr(srcPort), chr(destPort)));

    def cmdSendText(self, source, destination, srcPort, destPort, message):
        #print("{0}{1}{2}{3}".format(chr(destination), chr(srcPort), chr(destPort), message));
        self.sendCMD(
            self.CMD_MSG,
            source, "{0}{1}{2}{3}{4}".format(chr(destination), chr(srcPort),
                                             chr(destPort),
                                             chr(len(message) + 1), message))

    def cmdListUsr(self, source, port):
        #self.sendCMD (self.CMD_TEST_SERVER, address, port);
        self.sendCMD(self.CMD_LIST_USR, source, "{0}".format(chr(port)))
        # for the server at node [address] and [port], print all users connected
        #print 'Testing\n'
        #

    def cmbBroadCast(self, source, destination, srcPort, destPort, message):
        #print("{0}{1}{2}{3}".format(chr(destination), chr(srcPort), chr(destPort), message));
        self.sendCMD(
            self.CMD_MSG,
            source, "{0}{1}{2}{3}{4}".format(chr(destination), chr(srcPort),
                                             chr(destPort),
                                             chr(len(message) + 1), message))
class TestSim:
    moteids=[]
    # COMMAND TYPES
    CMD_PING = 0
    CMD_NEIGHBOR_DUMP = 1
    CMD_ROUTE_DUMP=3

    # CHANNELS - see includes/channels.h
    COMMAND_CHANNEL="command";
    GENERAL_CHANNEL="general";

    # Project 1
    NEIGHBOR_CHANNEL="neighbor";
    FLOODING_CHANNEL="flooding";

    # Project 2
    ROUTING_CHANNEL="routing";

    # Project 3
    TRANSPORT_CHANNEL="transport";

    # Personal Debuggin Channels for some of the additional models implemented.
    HASHMAP_CHANNEL="hashmap";

    # Initialize Vars
    numMote=0

    def __init__(self):
        self.t = Tossim([])
        self.r = self.t.radio()

        #Create a Command Packet
        self.msg = CommandMsg()
        self.pkt = self.t.newPacket()
        self.pkt.setType(self.msg.get_amType())

    # Load a topo file and use it.
    def loadTopo(self, topoFile):
        print 'Creating Topo!'
        # Read topology file.
        topoFile = 'topo/'+topoFile
        f = open(topoFile, "r")
        self.numMote = int(f.readline());
        print 'Number of Motes', self.numMote
        for line in f:
            s = line.split()
            if s:
                print " ", s[0], " ", s[1], " ", s[2];
                self.r.add(int(s[0]), int(s[1]), float(s[2]))
                if not int(s[0]) in self.moteids:
                    self.moteids=self.moteids+[int(s[0])]
                if not int(s[1]) in self.moteids:
                    self.moteids=self.moteids+[int(s[1])]

    # Load a noise file and apply it.
    def loadNoise(self, noiseFile):
        if self.numMote == 0:
            print "Create a topo first"
            return;

        # Get and Create a Noise Model
        noiseFile = 'noise/'+noiseFile;
        noise = open(noiseFile, "r")
        for line in noise:
            str1 = line.strip()
            if str1:
                val = int(str1)
            for i in self.moteids:
                self.t.getNode(i).addNoiseTraceReading(val)

        for i in self.moteids:
            print "Creating noise model for ",i;
            self.t.getNode(i).createNoiseModel()

    def bootNode(self, nodeID):
        if self.numMote == 0:
            print "Create a topo first"
            return;
        self.t.getNode(nodeID).bootAtTime(1333*nodeID);

    def bootAll(self):
        i=0;
        for i in self.moteids:
            self.bootNode(i);

    def moteOff(self, nodeID):
        self.t.getNode(nodeID).turnOff();

    def moteOn(self, nodeID):
        self.t.getNode(nodeID).turnOn();

    def run(self, ticks):
        for i in range(ticks):
            self.t.runNextEvent()

    # Rough run time. tickPerSecond does not work.
    def runTime(self, amount):
        self.run(amount*1000)

    # Generic Command
    def sendCMD(self, ID, dest, payloadStr):
        self.msg.set_dest(dest);
        self.msg.set_id(ID);
        self.msg.setString_payload(payloadStr)

        self.pkt.setData(self.msg.data)
        self.pkt.setDestination(dest)
        self.pkt.deliver(dest, self.t.time()+5)

    def ping(self, source, dest, msg):
        self.sendCMD(self.CMD_PING, source, "{0}{1}".format(chr(dest),msg));

    def neighborDMP(self, destination):
        self.sendCMD(self.CMD_NEIGHBOR_DUMP, destination, "neighbor command");

    def routeDMP(self, destination):
        self.sendCMD(self.CMD_ROUTE_DUMP, destination, "routing command");

    def addChannel(self, channelName, out=sys.stdout):
        print 'Adding Channel', channelName;
        self.t.addChannel(channelName, out);
Пример #7
0
class TestSim:
    moteids=[]
    # COMMAND TYPES
    CMD_PING = 0
    CMD_NEIGHBOR_DUMP = 1
    CMD_ROUTE_DUMP=3
    CMD_TEST_CLIENT = 4
    CMD_TEST_SERVER = 5
    CMD_CLIENT_CLOSE = 7
    CMD_APP_SERVER = 10
    CMD_APP_CLIENT = 11
    CMD_BROADCAST_MESSAGE = 12
    CMD_UNICAST_MESSAGE = 13
    CMD_PRINT_USERS= 14

    # CHANNELS - see includes/channels.h
    COMMAND_CHANNEL="command";
    GENERAL_CHANNEL="general";

    # Project 1
    NEIGHBOR_CHANNEL="neighbor";
    FLOODING_CHANNEL="flooding";

    # Project 2
    ROUTING_CHANNEL="routing";

    # Project 3
    TRANSPORT_CHANNEL="transport";

    # Personal Debuggin Channels for some of the additional models implemented.
    HASHMAP_CHANNEL="hashmap";

    # Initialize Vars
    numMote=0

    def __init__(self):
        self.t = Tossim([])
        self.r = self.t.radio()

        #Create a Command Packet
        self.msg = CommandMsg()
        self.pkt = self.t.newPacket()
        self.pkt.setType(self.msg.get_amType())

    # Load a topo file and use it.
    def loadTopo(self, topoFile):
        print 'Creating Topo!'
        # Read topology file.
        topoFile = 'topo/'+topoFile
        f = open(topoFile, "r")
        self.numMote = int(f.readline());
        print 'Number of Motes', self.numMote
        for line in f:
            s = line.split()
            if s:
                print " ", s[0], " ", s[1], " ", s[2];
                self.r.add(int(s[0]), int(s[1]), float(s[2]))
                if not int(s[0]) in self.moteids:
                    self.moteids=self.moteids+[int(s[0])]
                if not int(s[1]) in self.moteids:
                    self.moteids=self.moteids+[int(s[1])]

    # Load a noise file and apply it.
    def loadNoise(self, noiseFile):
        if self.numMote == 0:
            print "Create a topo first"
            return;

        # Get and Create a Noise Model
        noiseFile = 'noise/'+noiseFile;
        noise = open(noiseFile, "r")
        for line in noise:
            str1 = line.strip()
            if str1:
                val = int(str1)
            for i in self.moteids:
                self.t.getNode(i).addNoiseTraceReading(val)

        for i in self.moteids:
            print "Creating noise model for ",i;
            self.t.getNode(i).createNoiseModel()

    def bootNode(self, nodeID):
        if self.numMote == 0:
            print "Create a topo first"
            return;
        self.t.getNode(nodeID).bootAtTime(1333*nodeID);

    def bootAll(self):
        i=0;
        for i in self.moteids:
            self.bootNode(i);

    def moteOff(self, nodeID):
        self.t.getNode(nodeID).turnOff();

    def moteOn(self, nodeID):
        self.t.getNode(nodeID).turnOn();

    def run(self, ticks):
        for i in range(ticks):
            self.t.runNextEvent()

    # Rough run time. tickPerSecond does not work.
    def runTime(self, amount):
        self.run(amount*1000)

    # Generic Command
    def sendCMD(self, ID, dest, payloadStr):
        self.msg.set_dest(dest);
        self.msg.set_id(ID);
        self.msg.setString_payload(payloadStr)

        self.pkt.setData(self.msg.data)
        self.pkt.setDestination(dest)
        self.pkt.deliver(dest, self.t.time()+5)

    def ping(self, source, dest, msg):
        self.sendCMD(self.CMD_PING, source, "{0}{1}".format(chr(dest),msg));

    def neighborDMP(self, destination):
        self.sendCMD(self.CMD_NEIGHBOR_DUMP, destination, "neighbor command");

    def routeDMP(self, destination):
        self.sendCMD(self.CMD_ROUTE_DUMP, destination, "routing command");

    def addChannel(self, channelName, out=sys.stdout):
        print 'Adding Channel', channelName;
        self.t.addChannel(channelName, out);

    # def testClient(self, source, payload):
    #     self.sendCMD(self.CMD_TEST_CLIENT, source, payload);

    # def testServer(self, source, port):
    #     self.sendCMD(self.CMD_TEST_SERVER, source, port);

    def TestServer(self, address, port):
        self.sendCMD(self.CMD_TEST_SERVER, address, chr(port));

    def TestClient(self, source, sourcePort, destPort, dest, transfer):
        self.sendCMD(self.CMD_TEST_CLIENT, source, "{0}{1}{2}{3}".format(chr(dest),chr(sourcePort),chr(destPort),transfer));

    def ClientClose(self, clientAddr, destination, srcPort, destPort):
        self.sendCMD(self.CMD_CLIENT_CLOSE, clientAddr, "{0}{1}{2}".format(chr(destination),chr(srcPort),destPort));

    def AppServer(self, address):
        self.sendCMD(self.CMD_APP_SERVER, address, "app server command");

    def AppClient(self, address, username):
        self.sendCMD(self.CMD_APP_CLIENT, address, "{0}".format(username));

    def BroadcastMessage(self, address, message):
        self.sendCMD(self.CMD_BROADCAST_MESSAGE, address, "{0}".format(message));

    def UnicastMessage(self, client, username, msg):
        self.sendCMD(self.CMD_UNICAST_MESSAGE, client, "{0}{1}".format(username, msg));
        
    def printUsers():
        self.sendCMD(self.CMD_PRINT_USERS, client, "list command");
Пример #8
0
class TestSim:
    # COMMAND TYPES
    CMD_PING = 0
    CMD_NEIGHBOR_DUMP = 1
    CMD_LINKSTATE_DUMP = 2
    CMD_ROUTE_DUMP = 3
    CMD_TEST_CLIENT = 4
    CMD_TEST_SERVER = 5
    CMD_CLIENT_CLOSE = 6
    CMD_APP_LOGIN = 7
    CMD_APP_GLOBAL = 8
    CMD_APP_PRIVATE = 9
    CMD_APP_PRINTUSERS = 10
    CMD_APP_SET_SERVER = 11

    # CHANNELS - see includes/channels.h
    COMMAND_CHANNEL = "command"
    GENERAL_CHANNEL = "general"

    # Project 1
    NEIGHBOR_CHANNEL = "neighbor"
    FLOODING_CHANNEL = "flooding"

    # Project 2
    ROUTING_CHANNEL = "routing"

    # Project 3
    TRANSPORT_CHANNEL = "transport"

    # Personal Debuggin Channels for some of the additional models implemented.
    HASHMAP_CHANNEL = "hashmap"

    # Initialize Vars
    numMote = 0

    def __init__(self):
        self.t = Tossim([])
        self.r = self.t.radio()

        #Create a Command Packet
        self.msg = CommandMsg()
        self.pkt = self.t.newPacket()
        self.pkt.setType(self.msg.get_amType())

    # Load a topo file and use it.
    def loadTopo(self, topoFile):
        print 'Creating Topo!'
        # Read topology file.
        topoFile = 'topo/' + topoFile
        f = open(topoFile, "r")
        self.numMote = int(f.readline())
        print 'Number of Motes', self.numMote
        for line in f:
            s = line.split()
            if s:
                print " ", s[0], " ", s[1], " ", s[2]
                self.r.add(int(s[0]), int(s[1]), float(s[2]))

    # Load a noise file and apply it.
    def loadNoise(self, noiseFile):
        if self.numMote == 0:
            print "Create a topo first"
            return

        # Get and Create a Noise Model
        noiseFile = 'noise/' + noiseFile
        noise = open(noiseFile, "r")
        for line in noise:
            str1 = line.strip()
            if str1:
                val = int(str1)
            for i in range(1, self.numMote + 1):
                self.t.getNode(i).addNoiseTraceReading(val)

        for i in range(1, self.numMote + 1):
            print "Creating noise model for ", i
            self.t.getNode(i).createNoiseModel()

    def bootNode(self, nodeID):
        if self.numMote == 0:
            print "Create a topo first"
            return
        self.t.getNode(nodeID).bootAtTime(1333 * nodeID)

    def bootAll(self):
        i = 0
        for i in range(1, self.numMote + 1):
            self.bootNode(i)

    def moteOff(self, nodeID):
        self.t.getNode(nodeID).turnOff()

    def moteOn(self, nodeID):
        self.t.getNode(nodeID).turnOn()

    def run(self, ticks):
        for i in range(ticks):
            self.t.runNextEvent()

    # Rough run time. tickPerSecond does not work.
    def runTime(self, amount):
        self.run(amount * 1000)

    # Generic Command
    def sendCMD(self, ID, dest, payloadStr):
        self.msg.set_dest(dest)
        self.msg.set_id(ID)
        self.msg.setString_payload(payloadStr)

        self.pkt.setData(self.msg.data)
        self.pkt.setDestination(dest)
        self.pkt.deliver(dest, self.t.time() + 5)

    def ping(self, source, dest, msg):
        self.sendCMD(self.CMD_PING, source, "{0}{1}".format(chr(dest), msg))

    def neighborDMP(self, destination):
        self.sendCMD(self.CMD_NEIGHBOR_DUMP, destination, "neighbor command")

    def routeDMP(self, destination):
        self.sendCMD(self.CMD_ROUTE_DUMP, destination, "routing command")

    def linkstateDMP(self, destination):
        self.sendCMD(self.CMD_LINKSTATE_DUMP, destination,
                     "print link_table command")

    def testClient(self, source, destination, srcPort, destPort, transfer):
        self.sendCMD(
            self.CMD_TEST_CLIENT,
            source, "{0}{1}{2}{3}".format(chr(destination), chr(srcPort),
                                          chr(destPort), chr(transfer)))

    def testServer(self, destination, port):
        self.sendCMD(self.CMD_TEST_SERVER, destination, chr(port))

    def ClientClose(self, ClientAddress, destination, srcPort, destPort):
        self.sendCMD(
            self.CMD_CLIENT_CLOSE, source,
            "{0}{1}{2}".format(chr(destination), chr(srcPort), destPort))

    def appLogin(self, Source, ClientPort, Username):
        self.sendCMD(self.CMD_APP_LOGIN, Source,
                     "{0}{1}".format(chr(ClientPort), Username))

    def appSendGlobal(self, Source, Message):
        self.sendCMD(self.CMD_APP_GLOBAL, Source, Message)

    def appSendPrivate(self, Source, Username, Message):
        self.sendCMD(self.CMD_APP_PRIVATE, Source,
                     "{0}{1}".format(Username, Message))

    def setAppServer(self, destination):
        self.sendCMD(self.CMD_APP_SET_SERVER, destination, "setserver command")

    def appPrintUsers(self, Source):
        self.sendCMD(self.CMD_APP_PRINTUSERS, Source)

    def addChannel(self, channelName, out=sys.stdout):
        print 'Adding Channel', channelName
        self.t.addChannel(channelName, out)