len = 0
        for iface in self.interfaces:
            len += iface.length()
        return len

    def pack(self):
        return ''.join([intf.pack() for intf in self.interfaces])

    def __str__(self):
        return 'Hardware Info: %s' % ' || '.join(
            [str(intf) for intf in self.interfaces])


VNS_MESSAGES.append(VNSHardwareInfo)

VNS_PROTOCOL = LTProtocol(VNS_MESSAGES, 'I', 'I')


def create_vns_server(port,
                      recv_callback,
                      new_conn_callback,
                      lost_conn_callback,
                      verbose=True):
    """Starts a server which listens for VNS clients on the specified port.

    @param port  the port to listen on
    @param recv_callback  the function to call with received message content
                         (takes two arguments: transport, msg)
    @param new_conn_callback   called with one argument (a LTProtocol) when a connection is started
    @param lost_conn_callback  called with one argument (a LTProtocol) when a connection is lost
    @param verbose        whether to print messages when they are sent
예제 #2
0
    def __init__(self, request_type, flow_type, xid=0):
        Request.__init__(self, request_type, flow_type, xid)

    @staticmethod
    def unpack(body):
        return Request.unpack_child(FlowsRequest, body)

    def otype_to_str(self, otype):
        return Flow.type_to_str(otype)

    def __str__(self):
        return 'REQUEST for Flows: ' + Request.__str__(self)
OFG_MESSAGES.append(FlowsRequest)

OFG_PROTOCOL = LTProtocol(OFG_MESSAGES, 'H', 'B')

def create_ofg_server(port, recv_callback):
    """Starts a server which listens for OFG clients on the specified port.

    @param port  the port to listen on
    @param recv_callback  the function to call with received message content
                         (takes two arguments: transport, msg)

    @return returns the new LTTwistedServer
    """
    from ltprotocol.ltprotocol import LTTwistedServer
    server = LTTwistedServer(OFG_PROTOCOL, recv_callback)
    server.listen(port)
    return server
예제 #3
0
    def __str__(self):
        if self.problem_id == TIBadNodeOrPort.BAD_NODE:
            return 'Invalid node: %s' % self.node_name
        what = TINodePortHeader.__str__(self)
        if self.problem_id == TIBadNodeOrPort.BAD_INTF:
            return 'Invalid interface: %s' % what
        elif self.problem_id == TIBadNodeOrPort.MISSING_LINK:
            return 'There is no link connected to %s' % what
        else:
            return 'Unknown problem (code %d) with %s' % (self.problem_id,
                                                          what)


TI_MESSAGES.append(TIBadNodeOrPort)

TI_PROTOCOL = LTProtocol(TI_MESSAGES, 'H', 'H')


def create_ti_server(port,
                     recv_callback,
                     new_conn_callback,
                     lost_conn_callback,
                     verbose=True):
    """Starts a server which listens for TI clients on the specified port.

    @param port  the port to listen on
    @param recv_callback  the function to call with received message content
                         (takes two arguments: transport, msg)
    @param new_conn_callback   called with one argument (a LTProtocol) when a connection is started
    @param lost_conn_callback  called with one argument (a LTProtocol) when a connection is lost
    @param verbose        whether to print messages when they are sent
예제 #4
0
    def __init__(self, s):
        LTMessage.__init__(self)
        self.str = s

    def pack(self):
        return struct.pack("> %us" % len(self.str), self.str)

    @staticmethod
    def unpack(body):
        return StrMsg(struct.unpack("> %us" % len(body), body)[0])

    def __str__(self):
        return self.str

TEST_PROTOCOL = LTProtocol([NumMsg, StrMsg], 'H', 'B')
def print_ltm(prefix, proto, ltm):
    print '%s got: %s' % (prefix, str(ltm))

def print_disconnect(proto):
    print 'disconnected!'

if __name__ == "__main__":
    if len(sys.argv) < 2:
        print >> sys.stderr, "usage: ./test_ltprotocol.py TYPE"
        sys.exit(-1)

    what = sys.argv[1]
    if what != "client" and what != "server":
        print >> sys.stderr, "TYPE must be client or server"
        sys.exit(-1)