def sendToRP(myID, pktType, n, seq, recID, ndest, rdest, selectedRP, dests,
             data):
    #print("ndest was {}, preparing to send to RP".format(ndest))
    #If ndest > 1 then need to send information to RP
    #Send pkt to selectedRP
    emptyDests = dests.count(0)
    ndest = n - emptyDests
    datapkt = commonFunctions.createDataPacket(pktType, seq, recID, ndest,
                                               selectedRP, dests[0], dests[1],
                                               dests[2], data)
    nextHop = commonFunctions.getNextHop(myID, selectedRP)
    print(
        "Created PKT      pktType, seq, src, ndest, selectedRP, dests[0], dests[1], dests[2], data"
    )
    print(
        "with information   {}       {}  {}      {}      {}        {}       {}        {}      {}"
        .format(pktType, seq, recID, ndest, selectedRP, dests[0], dests[1],
                dests[2], data))
    routerFunctions.sendData(datapkt, nextHop, myID)
Пример #2
0
        time.sleep(1)
        """

        receivedPkt, addr = hostFunctions.receive_packet('0.0.0.0', 8888)
        #NEED to update function to move on after receiving ACK

        packetType = hostFunctions.decodePktType(receivedPkt)

        if(packetType == 7):
            seq, src, ndest, rdest, dest1, dest2, dest3, data = commonFunctions.decodeDataPkt(receivedPkt)
            print(data)
            hostFunctions.sendDataACK(addr[0])


    #create data packet
    pktType = 0x07
    src = myID
    seq = 0x01
    #k out of n destinations 1-3
    ndest = 3
    data = "This is a {} out of 3 multicast message".format(ndest)
    #rdest, dest1-3, will not be set when host sends pkt
    #Core router will determine those values
    #At this point the host should know the attached router
    #Does it make sense to send to that router or still broadcast like hellopkt?
    rdest = 0
    dest1 = 0
    dest2 = 0
    dest3 = 0
    datapkt = commonFunctions.createDataPacket(pktType, seq, src, ndest, rdest, dest1, dest2, dest3, data)
    #code to send datapkt
def rpFunction(myID, pktType, n, seq, recID, ndest, rdest, dest1, dest2, dest3,
               data):
    #print("router along path to multiple destinations, checking to see how to forward message along")
    #Assume RP functionality

    print(
        "Bifurcate Info   pktType, seq, src, ndest, rdest, dests[0], dests[1], dests[2], data"
    )
    print(
        "with information   {}       {}  {}      {}      {}        {}       {}        {}      {}"
        .format(pktType, seq, recID, ndest, rdest, dest1, dest2, dest3, data))

    #Get paths for
    dests = []
    destsPath = []
    for id in (dest for dest in [dest1, dest2, dest3] if dest != 0):
        dests.append(id)
        destsPath.append(routerFunctions.getPath(myID, id))

    #Check combinations of paths to see if next hop is the same
    lookaheadFlag = []
    index = range(len(destsPath))
    for a, b in itertools.combinations(index, 2):
        if destsPath[a][0] == destsPath[b][0]:
            lookaheadFlag.append([a, b])
        #print("DestPathA {}: {} DestPathB {}: {}".format(a,destPath[a][0], b, destPath[b][0]))

    #Determine how to send packets based on if other destinations
    #have the same next hop
    if len(lookaheadFlag) == len(destsPath):
        print(
            "all destinations have the same next hop, only sending one data packet"
        )
        #All messages going to same next hop
        ndest = len(dests)
        rdest = 0
        for ii in range(n - ndest):
            dests.append(0)
        datapkt = commonFunctions.createDataPacket(pktType, seq, recID, ndest,
                                                   rdest, dests[0], dests[1],
                                                   dests[2], data)
        nextHop = commonFunctions.getNextHop(myID, dests[0])
        print(
            "Created PKT      pktType, seq, src, ndest, rdest, dests[0], dests[1], dests[2], data"
        )
        print(
            "with information   {}       {}  {}      {}      {}        {}       {}        {}      {}"
            .format(pktType, seq, recID, ndest, rdest, dests[0], dests[1],
                    dests[2], data))
        routerFunctions.sendData(datapkt, nextHop, myID)

    else:
        print("Need to bifurcate, will split and send messages accordingly")
        #Just send dests[lookaheadFlag[0][0]] and dests[lookaheadFlag[0][1]] to gether but
        #not the other value
        #If this condition is hit there will only be one entry in the lookaheadFlag
        #send(dests[lookaheadFlag[0][0]] and dests[lookaheadFlag[0][1]])
        if len(lookaheadFlag) == 0:
            ndest = 1
            rdest = 0
            for id in dests:
                datapkt = commonFunctions.createDataPacket(
                    pktType, seq, recID, ndest, rdest, id, 0, 0, data)
                nextHop = commonFunctions.getNextHop(myID, id)
                print(
                    "Created PKT      pktType, seq, src, ndest, rdest, dests[0], dests[1], dests[2], data"
                )
                print(
                    "with information   {}       {}  {}      {}      {}        {}       {}        {}      {}"
                    .format(pktType, seq, recID, ndest, rdest, id, 0, 0, data))
                routerFunctions.sendData(datapkt, nextHop, myID)
        else:
            ndest = 2
            rdest = 0
            datapkt = commonFunctions.createDataPacket(
                pktType, seq, recID, ndest, rdest, dests[lookaheadFlag[0][0]],
                dests[lookaheadFlag[0][1]], 0, data)
            nextHop = commonFunctions.getNextHop(myID,
                                                 dests[lookaheadFlag[0][0]])
            print(
                "Created PKT      pktType, seq, src, ndest, rdest, dests[0], dests[1], dests[2], data"
            )
            print(
                "with information   {}       {}  {}      {}      {}        {}       {}        {}      {}"
                .format(pktType, seq, recID, ndest, rdest,
                        dests[lookaheadFlag[0][0]], dests[lookaheadFlag[0][1]],
                        0, data))
            routerFunctions.sendData(datapkt, nextHop, myID)
            if len(destsPath) == 3:
                dests.pop(lookaheadFlag[0][0])
                dests.pop(lookaheadFlag[0][1])
                ndest = 1
                datapkt = commonFunctions.createDataPacket(
                    pktType, seq, recID, ndest, rdest, dests[0], 0, 0, data)
                nextHop = commonFunctions.getNextHop(myID, dests[0])
                print(
                    "Created PKT      pktType, seq, src, ndest, rdest, dests[0], dests[1], dests[2], data"
                )
                print(
                    "with information   {}       {}  {}      {}      {}        {}       {}        {}      {}"
                    .format(pktType, seq, recID, ndest, rdest, dests[0], 0, 0,
                            data))
                routerFunctions.sendData(datapkt, nextHop, myID)


#rpFunction(201, 7, 3, 1, 101, 2, 0, 102, 103, 0, "This is a 2 out of 3 multicast message")
Пример #4
0
                #Assume Core Router functionality
                #If ndest is 1 unicast message to dest1
                #n from k out of n (hardcoded to 3 for this project)
                selectedRP, selectedDests = selectRP.selectRP(
                    ndest, n, myID, recID)
                dests = [0] * 3
                dests[0:len(selectedDests)] = selectedDests

                if (ndest == 1):
                    print(
                        "ndest was 1, preparing to send unicast to destination"
                    )
                    #send datapkt to dest1
                    selectedRP = 0
                    datapkt = commonFunctions.createDataPacket(
                        pktType, seq, recID, ndest, selectedRP, dests[0],
                        dests[1], dests[2], data)
                    nextHop = commonFunctions.getNextHop(myID, dests[0])
                    print(
                        "Created PKT      pktType, seq, src, ndest, rdest, dests[0], dests[1], dests[2], data"
                    )
                    print(
                        "with information   {}       {}   {}    {}       {}     {}       {}        {}        {}"
                        .format(pktType, seq, recID, ndest, selectedRP,
                                dests[0], dests[1], dests[2], data))
                    routerFunctions.sendData(datapkt, nextHop, myID)

                else:
                    if myID == selectedRP:
                        print("Core Router is also RP")
                        rdest = 0