Esempio n. 1
0
    def initASAs(self, registrar, proxy):
        ###################################
        # Main thread starts here
        ###################################

        grasp.tprint("==========================")
        grasp.tprint("GRASP Service is starting up.")
        grasp.tprint("==========================")

        #grasp.test_mode = True # tell everybody it's a test, will print extra diagnostics
        #time.sleep(1) # time to read the text

        ####################################
        # Register this ASA
        ####################################

        # The ASA name is arbitrary - it just needs to be
        # unique in the GRASP instance.

        grasp.skip_dialogue(False, False, True)
        _err, self._asa_nonce = grasp.register_asa("Pledge")
        if not _err:
            grasp.tprint("ASA Pledge registered OK")
        else:
            grasp.tprint("ASA registration failure:", grasp.etext[_err])
            exit()

        ####################################
        # Construct a GRASP objective
        ####################################

        # This is an empty GRASP objective to find the proxy
        # It's only used for get_flood so doesn't need to be filled in
        if proxy:
            proxy_obj = grasp.objective("AN_proxy")
            proxy_obj.synch = True
        else:
            proxy_obj = None

        if registrar:
            reg_obj = grasp.objective("AN_join_registrar")
            reg_obj.synch = True
        else:
            reg_obj = None
        return proxy_obj, reg_obj
Esempio n. 2
0
password = 0
confirm = 1
while password != confirm:
    password = bytes(getpass.getpass(), 'utf-8')
    confirm = bytes(getpass.getpass("Confirm: "), 'utf-8')
    if password != confirm:
        print("Mismatch, try again.")

####################################
# General initialisation
####################################

#time.sleep(8) # so the user can read the text

#this instance of GRASP must run unencrypted
grasp.skip_dialogue(selfing=True, quadsing=False)

#grasp.tprint("Encryption", grasp.crypto, "(should be False)")

####################################
# Register ASA/objectives
####################################

err, asa_nonce = grasp.register_asa("quadski")
if not err:
    grasp.tprint("ASA quadski registered OK")

else:
    exit()

keys_obj = grasp.objective("411:quadski")
Esempio n. 3
0
# AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED 
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A     
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
# THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)    
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING   
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE        
# POSSIBILITY OF SUCH DAMAGE.                         
#                                                     
########################################################
########################################################"""

import grasp
import time
print("Starting GRASP daemon without dialogue")
grasp.skip_dialogue(testing=True,
                    selfing=True,
                    quadsing=False,
                    diagnosing=True)
grasp._initialise_grasp()
grasp.init_bubble_text("GRASP daemon")
grasp.tprint("Daemon running")
while True:
    time.sleep(60)
Esempio n. 4
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")
Esempio n. 5
0
grasp.tprint("pusher is starting up.")
grasp.tprint("==========================")
grasp.tprint("pusher is a demonstration Autonomic Service Agent.")
grasp.tprint("It runs indefinitely as file transfer agent.")
grasp.tprint("It is implemented using a negotiation objective")
grasp.tprint("that can handle overlapping requests.")
grasp.tprint("On Windows or Linux, there should be a nice")
grasp.tprint("window that displays the process.")
grasp.tprint("==========================")

####################################
# General initialisation
####################################

time.sleep(8)  # so the user can read the text
grasp.skip_dialogue(selfing=True)

####################################
# Register ASA/objective
####################################

err, asa_nonce = grasp.register_asa("pusher")
if not err:
    grasp.tprint("ASA pusher registered OK")

else:
    exit()

supported_obj = grasp.objective("411:mvFile")
supported_obj.loop_count = 4
supported_obj.neg = True
Esempio n. 6
0
def main(args):
    ###################################
    # Main thread starts here
    ###################################

    grasp.tprint("==========================")
    grasp.tprint("Registrar initializing")
    grasp.tprint("==========================")

    grasp.test_mode = False  # set if you want detailed diagnostics
    #time.sleep(1) # time to read the text

    ####################################
    # Register this ASA
    ####################################

    # The ASA name is arbitrary - it just needs to be
    # unique in the GRASP instance. If you wanted to
    # run two registrars in one GRASP instance, they
    # would need different names. For example the name
    # could include a timestamp.
    grasp.skip_dialogue(False, False, True)
    _err, asa_nonce = grasp.register_asa("Reggie")
    #grasp.tprint("TYPE: ", type(asa_nonce))
    #.skip_dialogue(False,False,True)
    if not _err:
        grasp.tprint("ASA Registrar registered OK")
    else:
        grasp.tprint("ASA Registrar failure:", grasp.etext[_err])
        exit()  # demo code doesn't handle registration errors
    #grasp.skip_dialogue(False,False,True)

    ####################################
    # Create a TCP port for BRSKI-TCP
    ####################################

    # For this demo, we just make up some numbers:

    tcp_port = 80
    tcp_proto = socket.IPPROTO_TCP
    tcp_address = grasp._my_address  # current address determined by GRASP kernel

    ####################################
    # Construct a correponding GRASP ASA locator
    ####################################

    tcp_locator = grasp.asa_locator(tcp_address, None, False)
    tcp_locator.protocol = tcp_proto
    tcp_locator.port = tcp_port
    tcp_locator.is_ipaddress = True

    ####################################
    # Create a IPv4 port for BRSKI-IPv4
    ####################################

    # For this demo, we just make up some numbers:

    ipv4_port = 80
    ipv4_proto = socket.IPPROTO_TCP
    #ipv4_address = '172.2.13.0' #grasp._my_address # current address determined by GRASP kernel
    ipv4_address = findOwnIPv4()  # current address determined by GRASP kernel

    ####################################
    # Construct a correponding GRASP ASA locator
    ####################################

    ipv4_locator = grasp.asa_locator(ipv4_address, None, False)
    ipv4_locator.protocol = ipv4_proto
    ipv4_locator.port = ipv4_port
    #ipv4_locator.is_ipaddress = True
    ipv4_locator.is_fqdn = True

    ####################################
    # Construct the GRASP objective
    ####################################

    radius = 255  # Limit the radius of flooding

    reg_obj = grasp.objective("AN_join_registrar")
    reg_obj.loop_count = radius
    reg_obj.synch = True  # needed for flooding
    reg_obj.value = None

    ####################################
    # Register the GRASP objective
    ####################################

    _err = grasp.register_obj(asa_nonce, reg_obj)
    if not _err:
        grasp.tprint("Objective", reg_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("BRSKI Join Registrar (flooding method)")
    grasp.tprint("==========================")
    grasp.tprint("Registrar starting now")
    grasp.tprint("==========================")

    ####################################
    # Start flooding thread
    ####################################

    f = flooder(reg_obj, ipv4_locator, asa_nonce)
    f.start()
    #flooder().start()
    grasp.tprint("Flooding", reg_obj.name, "for ever")

    ###################################
    # Listen for requests
    ###################################

    # Here, launch a thread to do the real work of the registrar
    # via the various ports But for the demo, we just pretend...
    #grasp.tprint("Pretending to listen to ports", tcp_port,",", udp_port,
    #             "and for IP-in-IP")

    ###################################
    # Do whatever needs to be done in the main thread
    ###################################

    # At a minimum, the main thread should keep an eye
    # on the other threads and restart them if needed.
    # For the demo, we just dump some diagnostic data...

    try:
        while True:
            time.sleep(5)
            #grasp.tprint("Registrar main loop diagnostic dump:")
            #dump_some()
    except KeyboardInterrupt:
        print('interrupted!')
        grasp.tprint("EXITTING")
        f.stop()
        exit()
Esempio n. 7
0
#grasp.tprint('modulo an error in the "AN_proxy" definition')
grasp.tprint("On Windows or Linux, there should soon be")
grasp.tprint("a nice window that displays the process.")
grasp.tprint("==========================")

#grasp.test_mode = True # tell everybody it's a test, will print extra diagnostics
time.sleep(1)  # time to read the text

####################################
# Register this ASA
####################################

# The ASA name is arbitrary - it just needs to be
# unique in the GRASP instance.

grasp.skip_dialogue(False, False, True)
_err, _asa_nonce = grasp.register_asa("Procksy")
if not _err:
    grasp.tprint("ASA Procksy registered OK")
else:
    grasp.tprint("ASA registration failure:", grasp.etext[_err])
    exit()

####################################
# Construct a GRASP objective
####################################

# This is an empty GRASP objective to find the registrar
# It's only used for get_flood so doesn't need to be filled in

reg_obj = grasp.objective("AN_join_registrar")