RestComm / jss7

RestComm Java SS7 Stack and Services
http://www.restcomm.com/
GNU Affero General Public License v3.0
177 stars 218 forks source link

TCAPID byte swapping #293

Closed faizann closed 6 years ago

faizann commented 6 years ago

FEATURE REQUEST:

What happened:

TCAPStack swaps bytes to change the endianess of the TCAPID. This makes it difficult to match TCAPID for routing in STPs. Some STPs expect TCAPID to be in little endian and such byte swapping makes it impossible to match TCAPIDs within a range.

What you expected to happen:

TCAPID if left unchanged (unswapped) matches the TCAPID range on the STP.

How to reproduce it (as minimally and precisely as possible):

We can see that in the traces that the most significant byte is on the right side of the TCAPID OCTET STRING.

Anything else we need to know?:

Environment:

Proposed Feature :

We would prefer a configurable flag that enables/disables this byte swapping feature of TCAP Stack. The code change is very minimum and requires change in utils.java to accept a flag to swap or not-swap the bytes.

    public static long decodeTransactionId(byte[] data) {
        byte[] longRep = new byte[8];
        // copy data so longRep = {0,0,0,...,data};
        System.arraycopy(data, 0, longRep, longRep.length - data.length, data.length);
        ByteBuffer bb = ByteBuffer.wrap(longRep);
        return bb.getLong();

    }

    public static byte[] encodeTransactionId(long txId) {
        // txId may only be up to 4 bytes, that is 0xFF FF FF FF
        byte[] data = new byte[4];
        // long ll = txId.longValue();
        // data[3] = (byte) ll;
        // data[2] = (byte) (ll>> 8);
        // data[1] = (byte) (ll>>16);
        // data[0] = (byte) (ll >> 24);
        data[3] = (byte) txId;
        data[2] = (byte) (txId >> 8);
        data[1] = (byte) (txId >> 16);
        data[0] = (byte) (txId >> 24);

        return data;
    }
gsaslis commented 6 years ago

Adding an extra flag sounds like a valid approach.

@RestComm/messaging-squad what do you think?

knosach commented 6 years ago

hi @faizann will you be able to create PR for this issue?

faizann commented 6 years ago

Hi @knosach Yes. Already working on it and should be done by end of this week.

knosach commented 6 years ago

closed in https://github.com/RestComm/jss7/commit/da9d007c32b1eca6157d4addaecbe3d626da8d07 closed in https://github.com/RestComm/jss7/commit/66b66860a794e284524fcf47b87566904179eaff