Exemple #1
0
def floodout(registrar):

    r_addr = registrar.locator
    r_port = registrar.port
    r_proto = registrar.protocol
    grasp.tprint("Chose registrar", r_addr, r_proto, r_port)

    ###################################
    # Finalise the locator
    ###################################

    proxy_locator.protocol = registrar.protocol
    if registrar.protocol == socket.IPPROTO_TCP:
        proxy_locator.port = t_port
    elif registrar.protocol == socket.IPPROTO_UDP:
        proxy_locator.port = u_port
    elif registrar.protocol == socket.IPPROTO_IPV6:
        proxy_locator.port = 0
    else:
        return  # unknown method

    ###################################
    # Flood it out for the pledges
    ###################################

    grasp.tprint("Flooding", proxy_obj.name, proxy_locator.locator,
                 proxy_locator.protocol, proxy_locator.port)
    grasp.flood(_asa_nonce, proxy_ttl,
                grasp.tagged_objective(proxy_obj, proxy_locator))
    return
Exemple #2
0
 def run(self):
     while True:
         time.sleep(60)
         obj1.value = datetime.datetime.utcnow().strftime(
             "%Y-%m-%d %H:%M UTC from Briggs")
         grasp.flood(asa_nonce, 59000, grasp.tagged_objective(obj1, None))
         time.sleep(5)
         if grasp.test_mode:
             dump_some()
Exemple #3
0
    def run(self):
        while self.running:

            self.reg_obj.value = "EST-TLS"
            grasp.tprint("FLOODING IDENTIFIER: ", self.locator.locator,
                         " | IS IPv6: ", self.locator.is_ipaddress)
            #grasp.flood(asa_nonce, 120000,
            #            grasp.tagged_objective(reg_obj,tcp_locator))
            grasp.flood(self.asa_nonce, 120000,
                        grasp.tagged_objective(self.reg_obj, self.locator))
            time.sleep(10)
Exemple #4
0
 def run(self):
     while True:
         time.sleep(60)
         obj1.value = datetime.datetime.utcnow().strftime(
             "%Y-%m-%d %H:%M UTC from Briggs")
         err = grasp.flood(asa_nonce, 59000,
                           [grasp.tagged_objective(obj1, None)])
         if err:
             grasp.tprint("Flood failure:", grasp.etext[err])
         time.sleep(5)
         if grasp.test_mode:
             dump_some()
Exemple #5
0
    grasp.tprint("Objective registration failure:", grasp.etext[_err])
    exit()  # demo code doesn't handle registration errors

####################################
# Start pretty printing
####################################

grasp.init_bubble_text("ACP container")
grasp.tprint("ACPcontainer starting now")

###################################
# Now flood the objectives out at
# a suitable frequency
###################################

while True:
    acp_locator.port = 500 + grasp._prng.randint(0,
                                                 5)  #slightly random for demo
    est_locator.port = 80 + grasp._prng.randint(0, 5)
    grasp.tprint("Flooding", acp_obj.name, acp_locator.protocol,
                 acp_locator.port, "and", est_obj.name, est_locator.protocol,
                 est_locator.port)
    grasp.flood(_asa_nonce, acp_ttl,
                grasp.tagged_objective(acp_obj, acp_locator),
                grasp.tagged_objective(est_obj, est_locator))
    ##    grasp.flood(_asa_nonce, est_ttl, grasp.tagged_objective(est_obj, est_locator))

    time.sleep(60)  #The default SHOULD be 60 seconds, the
    #value SHOULD be operator configurable.
    #(configure here with your preferred editor)
Exemple #6
0
 def run(self):
     grasp.tprint("Flooding", obj2.name, "for ever")
     while True:
         time.sleep(60)
         grasp.flood(asa_nonce, 59000, grasp.tagged_objective(obj2, None))
         time.sleep(5)
Exemple #7
0
_err = grasp.register_obj(_asa_nonce, acp_obj)
if not _err:
    grasp.tprint("Objective", acp_obj.name, "registered OK")
else:
    grasp.tprint("Objective registration failure:", grasp.etext[_err])
    exit()  # demo code doesn't handle registration errors

####################################
# Start pretty printing
####################################

grasp.init_bubble_text("ACP container")
grasp.tprint("ACPcontainer starting now")

###################################
# Now flood the objective out at
# a suitable frequency
###################################

while True:
    acp_locator.port = 500 + grasp._prng.randint(0,
                                                 5)  #slightly random for demo
    grasp.tprint("Flooding", acp_obj.name, acp_locator.protocol,
                 acp_locator.port)
    grasp.flood(_asa_nonce, acp_ttl,
                grasp.tagged_objective(acp_obj, acp_locator))

    time.sleep(60)  #The default SHOULD be 60 seconds, the
    #value SHOULD be operator configurable.
    #(configure here with your preferred editor)
Exemple #8
0
 def run(self):
     while True:
         grasp.flood(asa_nonce, 120000,
                     grasp.tagged_objective(flood_obj, None))
         time.sleep(60)
Exemple #9
0
    def run(self):
        time.sleep(1)  # avoid printing glitch
        grasp.tprint(
            "WARNING: you can't run this test suite more than once without restarting the Python context; it leaves GRASP data structures dirty!\n"
        )
        grasp.skip_dialogue(testing=True, selfing=True, diagnosing=True)
        time.sleep(1)  # just to avoid mixed up print output

        ####################################
        # Test code: register ASA/objective#
        ####################################

        test_obj = grasp.objective("EX1")
        test_obj.loop_count = 2
        test_obj.synch = True
        err, test_nonce = grasp.register_asa("ASA-1")
        if not err:
            err = grasp.register_obj(test_nonce, test_obj, ttl=10000)
            if not err:
                grasp.tprint("ASA-1 and EX1 Registered OK")

####################################
# Test code: discover EX1          #
####################################

        err, test_ll = grasp.discover(test_nonce, test_obj, 10000)
        if len(test_ll) > 0:
            grasp.tprint("EX1 discovery result", test_ll[0].locator)
        else:
            grasp.tprint("No EX1 discovery response")

####################################
# Test code: register and discover #
# Boot ASA/objective               #
####################################

        err, boot_nonce = grasp.register_asa("Boot")
        if err:
            #we've got a problem...
            raise RuntimeError("Can't register Boot as ASA")

        boot_obj = grasp.objective("Boot")
        boot_obj.loop_count = 2
        boot_obj.synch = True
        err = grasp.register_obj(boot_nonce, boot_obj, discoverable=True)

        if err:
            #we've got a different problem...
            raise RuntimeError("Can't register Boot objective")

        for i in range(3):
            #test discovery 3 times, including artificial Divert
            grasp.tprint("Test ASA: grasp.test_divert", grasp.test_divert)
            err, boot_ll = grasp.discover(boot_nonce, boot_obj, 5000)
            if len(boot_ll) > 0:
                grasp.tprint("Boot discovery result", boot_ll[0].locator)
                grasp.test_divert = True
            else:
                grasp.tprint("No Boot discovery response")
            time.sleep(5)
        grasp.test_divert = False

        ####################################
        # Test code: send Flood messages
        ####################################

        obj1 = grasp.objective("Money")
        obj1.synch = True
        obj1.loop_count = 2
        err = grasp.register_obj(test_nonce, obj1)
        obj1.value = [100, "NZD"]

        obj2 = grasp.objective("Bling")
        obj2.synch = True
        obj2.loop_count = 2
        err = grasp.register_obj(test_nonce, obj2)
        obj2.value = ["Diamonds", "Rubies"]
        err = grasp.register_obj(test_nonce, obj2)
        if err:
            grasp.tprint(grasp.etext[err])

        obj3 = grasp.objective("Intent.PrefixManager")
        obj3.synch = True
        obj3.loop_count = 2
        err = grasp.register_obj(test_nonce, obj3)
        #obj3.value = '{"autonomic_intent":[{"model_version": "1.0"},{"intent_type": "Network management"},{"autonomic_domain": "Customer_X_intranet"},{"intent_name": "Prefix management"},{"intent_version": 73},{"Timestamp": "20150606 00:00:00"},{"Lifetime": "Permanent"},{"signature":"XXXXXXXXXXXXXXXXXXX"},{"content":[{"role": [{"role_name": "RSG"},{"role_characteristic":[{"prefix_length":"34"}]}]},{"role": [{"role_name": "ASG"},{"role_characteristic":[{"prefix_length": "44"}]}]},{"role": [{"role_name": "CSG"},{"role_characteristic":[{"prefix_length": "56"}]}]}]}]}'

        #obj3.value = '{"autonomic_intent dummy text"}'
        #obj3.value = bytes.fromhex('48deadbeefdeadbeef') #dummy CBOR
        obj3.value = cbor.dumps(["Some", "embedded", "CBOR", [1, 2, 3]])

        grasp.flood(test_nonce, 0, grasp.tagged_objective(obj1, None),
                    grasp.tagged_objective(obj2, None),
                    grasp.tagged_objective(obj3, None))

        ###################################
        # Test code: Listen Synchronize as from Boot ASA
        ###################################

        boot_obj.value = [1, "two", 3]
        boot_obj.synch = True
        err = grasp.listen_synchronize(boot_nonce, boot_obj)
        grasp.tprint("Listen synch", grasp.etext[err])
        grasp.tprint(grasp._obj_registry[1].objective.name, "value",
                     grasp._obj_registry[1].objective.value)

        ###################################
        # Test code: call Synchronize as from EX1
        ###################################
        time.sleep(5)

        err, result = grasp.synchronize(test_nonce, obj2, None, 5000)
        if not err:
            grasp.tprint("Flooded synch obj2", result.value)
        else:
            grasp.tprint("Synch fail obj2", grasp.etext[err])

        err, result = grasp.synchronize(test_nonce, obj3, None, 5000)
        if not err:
            grasp.tprint("Flooded synch obj3", result.value)
        else:
            grasp.tprint("Synch fail obj3", grasp.etext[err])

        #this should fail as test_obj was neither flooded or listened for.
        err, result = grasp.synchronize(test_nonce, test_obj, None, 5000)
        if not err:
            grasp.tprint("Synch test_obj (should fail)", result.value)
        else:
            grasp.tprint("Synch fail test_obj (should fail)", grasp.etext[err])

        boot2_obj = grasp.objective("Boot")
        boot2_obj.synch = True

        err, result = grasp.synchronize(test_nonce, boot2_obj, None, 5000)
        if not err:
            grasp.tprint("Synch boot2_obj", result.name, result.value)
        else:
            grasp.tprint("Synch fail boot2_obj", grasp.etext[err])

###################################
# Test code: print obj_registry
# and flood cache
###################################

        grasp.tprint("Objective registry contents:")
        for x in grasp._obj_registry:
            o = x.objective
            grasp.tprint(o.name, "ASA:", x.asa_id, "Listen:", x.listening,
                         "Neg:", o.neg, "Synch:", o.synch, "Count:",
                         o.loop_count, "Value:", o.value)
        grasp.tprint("Flood cache contents:")
        for x in grasp._flood_cache:
            grasp.tprint(x.objective.name, "count:", x.objective.loop_count,
                         "value:", x.objective.value, "source:", x.source)
        time.sleep(5)

        ###################################
        # Test code: check flood cache for Tag 24 case
        ###################################

        flobj = grasp.objective("Intent.PrefixManager")
        flobj.synch = True
        err, tobs = grasp.get_flood(test_nonce, flobj)
        if not err:
            for x in tobs:
                try:
                    grasp.tprint("Flooded CBOR", x.objective.name,
                                 cbor.loads(x.objective.value))
                except:
                    grasp.tprint("Flooded raw", x.objective.name,
                                 x.objective.value)

###################################
# Test code: deregister and then
# attempt synch
###################################

        err = grasp.deregister_obj(boot_nonce, boot_obj)
        if not err:
            grasp.tprint("Deregistered Boot", )
        else:
            grasp.tprint("Deregister failure", grasp.etext[err])

        err, result = grasp.synchronize(test_nonce, boot2_obj, None, 5000)
        if not err:
            grasp.tprint("Synch boot2_obj (should fail)", result.name,
                         result.value)
        else:
            grasp.tprint("Synch fail boot2_obj (should fail)",
                         grasp.etext[err])

###################################
# Test code: start in-host negotiate test
###################################
        cheat_nonce = None
        Neg1().start()
        time.sleep(10)
        Neg2().start()

        #####################################
        # Test code:
        # test deregistering an ASA,
        # and exit the thread
        #####################################

        grasp.deregister_asa(test_nonce, "ASA-1")
        grasp.tprint("Exiting ASA test thread")
Exemple #10
0
 def run(self):
     while True:
         time.sleep(60)
         reg_obj.value = "EST-TLS"
         grasp.flood(asa_nonce, 120000,
                     grasp.tagged_objective(reg_obj, tcp_locator))