示例#1
0
    async def main(self):
        yang_data = {
              "ietf-taps-api:preconnection":{
                "local-endpoints":[
                  {
                    "id":"1",
                    "local-address":str(self.addr),
                    "local-port":str(self.port),
                  }
                ]
              }
            }

        self.preconnection = taps.Preconnection.from_yang(taps.yang_validate.YANG_FMT_JSON, json.dumps(yang_data, indent=4));

        if self.trust_ca or self.local_identity:
            sp = taps.SecurityParameters()
            if self.trust_ca:
                sp.addTrustCA(self.trust_ca)
            if self.local_identity:
                sp.addIdentity(self.local_identity)
            self.preconnection.security_parameters = sp

        self.preconnection.on_connection_received(
                self.handle_connection_received)
        self.preconnection.on_listen_error(self.handle_listen_error)
        self.preconnection.on_stopped(self.handle_stopped)
        await self.preconnection.listen()
    async def main(self, args):

        # Create endpoint objects
        ep = taps.RemoteEndpoint()
        if args.remote_address:
            ep.with_address(args.remote_address)
        elif args.remote_host:
            ep.with_hostname(args.remote_host)
        if args.remote_port:
            ep.with_port(args.remote_port)
        lp = None
        sp = None
        if args.interface or args.local_address or args.local_port:
            lp = taps.LocalEndpoint()
            if args.interface:
                lp.with_interface(args.interface)
            if args.local_address:
                lp.with_port(args.local_address)
            if args.local_port:
                lp.with_port(args.local_port)

        logger.info("Created endpoint objects.")

        if args.secure or args.trust_ca or args.local_identity:
            # Use TLS
            sp = taps.SecurityParameters()
            if args.trust_ca:
                sp.add_trust_ca(args.trust_ca)
            if args.local_identity:
                sp.add_identity(args.local_identity)
            logger.info("Created SecurityParameters.")

        # Create transportProperties Object and set properties
        # Does nothing yet
        tp = taps.TransportProperties()
        # tp.prohibit("reliability")
        tp.ignore("congestion-control")
        tp.ignore("preserve-order")
        # tp.add("Reliable_Data_Transfer", taps.preferenceLevel.REQUIRE)

        # Create the preconnection object with the two prev created EPs
        self.preconnection = taps.Preconnection(remote_endpoint=ep,
                                                local_endpoint=lp,
                                                transport_properties=tp,
                                                security_parameters=sp)
        # Set callbacks
        self.preconnection.on_initiate_error(self.handle_initiate_error)
        self.preconnection.on_ready(self.handle_ready)
        # Set the framer
        framer = TestFramer()
        self.preconnection.add_framer(framer)
        logger.info("Created preconnection object and set cbs.")
        # Initiate the connection
        self.connection = await self.preconnection.initiate()
        # msgref = await self.connection.send_message("Hello\n")
        logger.info("Called initiate, connection object created.")
    async def main(self,
                   data_to_send="Hello\n",
                   stop_at_sent=False,
                   remote_hostname="localhost",
                   remote_port=6666,
                   reliable=False,
                   yangfile=None,
                   trust_ca=None,
                   local_identity=None):
        self.data_to_send = data_to_send
        self.stop_at_sent = stop_at_sent
        self.yangfile = yangfile

        ep = taps.RemoteEndpoint()
        ep.with_hostname(remote_hostname)
        ep.with_port(remote_port)
        tp = taps.TransportProperties()

        if not reliable:
            tp.prohibit("reliability")
        tp.ignore("congestion-control")
        tp.ignore("preserve-order")

        if trust_ca or local_identity:
            sp = taps.SecurityParameters()
            if trust_ca:
                sp.addTrustCA(trust_ca)
            if local_identity:
                sp.addIdentity(local_identity)
        else:
            sp = None

        if self.yangfile:
            self.preconnection = taps.\
                Preconnection.from_yangfile(self.yangfile,
                                            remote_endpoint=ep,
                                            transport_properties=tp,
                                            security_parameters=sp,
                                            event_loop=asyncio.get_event_loop()
                                            )
        else:
            self.preconnection = taps.\
                Preconnection(remote_endpoint=ep,
                              transport_properties=tp,
                              security_parameters=sp,
                              event_loop=asyncio.get_event_loop()
                              )

        self.preconnection.on_ready(self.handle_ready)
        self.connection = await self.preconnection.initiate()
    async def main(self, args):
        # Create endpoint object
        lp = taps.LocalEndpoint()
        if args.interface:
            lp.with_interface(args.interface)
        if args.local_address:
            lp.with_address(args.local_address)
        if args.local_host:
            lp.with_hostname(args.local_host)
        # If nothing to listen on has been specified, listen on localhost
        if not args.interface and not args.local_address\
           and not args.local_host:
            lp.with_hostname("localhost")
        if args.local_port:
            lp.with_port(args.local_port)

        taps.print_time("Created endpoint objects.", color)

        sp = None
        if args.secure or args.trust_ca or args.local_identity:
            # Use TLS
            sp = taps.SecurityParameters()
            if args.trust_ca:
                sp.addTrustCA(args.trust_ca)
            if args.local_identity:
                sp.addIdentity(args.local_identity)
            taps.print_time("Created SecurityParameters.", color)

        tp = taps.TransportProperties()
        tp.ignore("congestion-control")
        tp.ignore("preserve-order")
        if self.reliable == "False":
            tp.prohibit("reliability")
        if self.reliable == "Both":
            tp.ignore("reliability")

        self.preconnection = taps.Preconnection(local_endpoint=lp,
                                                transport_properties=tp,
                                                security_parameters=sp)
        self.preconnection.on_connection_received(
            self.handle_connection_received)
        self.preconnection.on_listen_error(self.handle_listen_error)
        self.preconnection.on_stopped(self.handle_stopped)
        # self.preconnection.frame_with(taps.TlvFramer())
        await self.preconnection.listen()