Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3dd5b070 authored by Sewook Seo's avatar Sewook Seo
Browse files

QoS filtering based on Protocol ID

Support QoS filter Protocol ID. Find proper callback listener based on
protocol ID included in QoS filter from network.

Bug: 246227644
Test: atest FrameworksTelephonyTests
Change-Id: I11f1ac0c13ba6924a88ec1f5bda165caec1f5d8c
Merged-In: I11f1ac0c13ba6924a88ec1f5bda165caec1f5d8c
parent 356e5732
Loading
Loading
Loading
Loading
+38 −1
Original line number Diff line number Diff line
@@ -80,12 +80,20 @@ public class QosCallbackTracker extends Handler {
        /**
         * Filter using the remote address.
         *
         * @param address The local address.
         * @param address The remote address.
         * @param startPort Starting port.
         * @param endPort Ending port.
         * @return {@code true} if matches, {@code false} otherwise.
         */
        boolean matchesRemoteAddress(InetAddress address, int startPort, int endPort);

        /**
         * Filter using the protocol
         *
         * @param protocol ID
         * @return {@code true} if matches, {@code false} otherwise.
         */
        boolean matchesProtocol(int protocol);
    }

    /**
@@ -124,6 +132,11 @@ public class QosCallbackTracker extends Handler {
                                        return filter.matchesRemoteAddress(address, startPort,
                                                endPort);
                                    }

                                    @Override
                                    public boolean matchesProtocol(int protocol) {
                                        return filter.matchesProtocol(protocol);
                                    }
                                });
                    }

@@ -332,6 +345,21 @@ public class QosCallbackTracker extends Handler {
        return result;
    }

    private boolean matchesByProtocol(@NonNull QosBearerFilter sessionFilter,
            final @NonNull IFilter filter, boolean hasMatchedFilter) {
        boolean result = false;
        int protocol = sessionFilter.getProtocol();
        if (protocol == QosBearerFilter.QOS_PROTOCOL_TCP
                || protocol == QosBearerFilter.QOS_PROTOCOL_UDP) {
            result = filter.matchesProtocol(protocol);
        } else {
            // FWK currently doesn't support filtering based on protocol ID ESP & AH. We will follow
            // match results of other filters.
            result = hasMatchedFilter;
        }
        return result;
    }

    private QosBearerFilter getFilterByPrecedence(
            @Nullable QosBearerFilter qosFilter, QosBearerFilter sessionFilter) {
        // Find for the highest precedence filter, lower the value is the higher the precedence
@@ -362,6 +390,15 @@ public class QosCallbackTracker extends Handler {
                    hasMatchedFilter = true;
                }
            }

            if (sessionFilter.getProtocol() != QosBearerFilter.QOS_PROTOCOL_UNSPECIFIED) {
                if (!matchesByProtocol(sessionFilter, filter, hasMatchedFilter)) {
                    unMatched = true;
                } else {
                    hasMatchedFilter = true;
                }
            }

            if (!unMatched && hasMatchedFilter) {
                qosFilter = getFilterByPrecedence(qosFilter, sessionFilter);
            }
+81 −1
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ public class QosCallbackTrackerTest extends TelephonyTest {
    class Filter implements QosCallbackTracker.IFilter {
        InetSocketAddress mLocalAddress;
        InetSocketAddress mRemoteAddress;
        int mProtocol = QosBearerFilter.QOS_PROTOCOL_TCP;

        Filter(@NonNull final InetSocketAddress localAddress) {
            this.mLocalAddress = localAddress;
@@ -87,6 +88,10 @@ public class QosCallbackTrackerTest extends TelephonyTest {
                    && endPort >= mRemoteAddress.getPort()
                    && (address.isAnyLocalAddress() || mRemoteAddress.getAddress().equals(address));
        }

        public boolean matchesProtocol(int protocol) {
            return mProtocol == protocol;
        }
    }

    // Mocked classes
@@ -151,6 +156,13 @@ public class QosCallbackTrackerTest extends TelephonyTest {
    private static QosBearerFilter createIpv4QosFilter(String localAddress, String remoteAddress,
            QosBearerFilter.PortRange localPort, QosBearerFilter.PortRange remotePort,
            int precedence) {
        return createIpv4QosFilter(localAddress, remoteAddress, localPort, remotePort,
                QosBearerFilter.QOS_PROTOCOL_TCP, precedence);
    }

    private static QosBearerFilter createIpv4QosFilter(String localAddress, String remoteAddress,
            QosBearerFilter.PortRange localPort, QosBearerFilter.PortRange remotePort, int protocol,
            int precedence) {
        ArrayList<LinkAddress> localAddresses = new ArrayList<>();
        if (localAddress != null) {
            localAddresses.add(
@@ -163,7 +175,7 @@ public class QosCallbackTrackerTest extends TelephonyTest {
        }
        return new QosBearerFilter(
                localAddresses, remoteAddresses, localPort, remotePort,
                QosBearerFilter.QOS_PROTOCOL_TCP, 7, 987, 678,
                protocol, 7, 987, 678,
                QosBearerFilter.QOS_FILTER_DIRECTION_BIDIRECTIONAL, precedence);
    }

@@ -541,6 +553,74 @@ public class QosCallbackTrackerTest extends TelephonyTest {
        verify(mINetworkAgentRegistry, times(1)).sendQosSessionLost(eq(1), any(QosSession.class));
    }

    @Test
    public void testQosSessionFilterProtocol() throws Exception {
        // QosBearerFilter including protocol
        ArrayList<QosBearerFilter> qosFilters1 = new ArrayList<>();
        qosFilters1.add(createIpv4QosFilter(null, null, null,
                new QosBearerFilter.PortRange(3200, 3220), QosBearerFilter.QOS_PROTOCOL_UDP, 45));
        ArrayList<QosBearerSession> qosSessions = new ArrayList<>();
        qosSessions.add(new QosBearerSession(1234, createEpsQos(5, 6, 7, 8), qosFilters1));

        mQosCallbackTracker.updateSessions(qosSessions);

        // Add filter after updateSessions
        Filter filter = new Filter(new InetSocketAddress(
                InetAddresses.parseNumericAddress("122.22.22.22"), 1357),
                new InetSocketAddress(InetAddresses.parseNumericAddress("177.77.77.77"), 3207));
        mQosCallbackTracker.addFilter(1, filter);
        processAllMessages();
        verify(mINetworkAgentRegistry, never()).sendEpsQosSessionAvailable(eq(1),
                any(QosSession.class), any(EpsBearerQosSessionAttributes.class));

        // Remove the matching QosBearerFilter
        qosSessions.remove(0);
        mQosCallbackTracker.updateSessions(qosSessions);
        processAllMessages();
        verify(mINetworkAgentRegistry, never()).sendQosSessionLost(eq(1), any(QosSession.class));

        qosFilters1.clear();
        qosFilters1.add(createIpv4QosFilter(null, null, null,
                new QosBearerFilter.PortRange(3200, 3220), QosBearerFilter.QOS_PROTOCOL_TCP, 45));
        qosSessions.clear();
        qosSessions.add(new QosBearerSession(1234, createEpsQos(5, 6, 7, 8), qosFilters1));
        mQosCallbackTracker.updateSessions(qosSessions);
        processAllMessages();
        verify(mINetworkAgentRegistry, times(1)).sendEpsQosSessionAvailable(eq(1),
                any(QosSession.class), any(EpsBearerQosSessionAttributes.class));
        qosSessions.remove(0);
        mQosCallbackTracker.updateSessions(qosSessions);
        processAllMessages();
        verify(mINetworkAgentRegistry, times(1)).sendQosSessionLost(eq(1), any(QosSession.class));
    }

    @Test
    public void testQosSessionFilterProtocolEsp() throws Exception {
        // QosBearerFilter including protocol
        ArrayList<QosBearerFilter> qosFilters1 = new ArrayList<>();
        qosFilters1.add(createIpv4QosFilter(null, null, null,
                new QosBearerFilter.PortRange(3200, 3220), QosBearerFilter.QOS_PROTOCOL_ESP, 45));
        ArrayList<QosBearerSession> qosSessions = new ArrayList<>();
        qosSessions.add(new QosBearerSession(1234, createEpsQos(5, 6, 7, 8), qosFilters1));

        mQosCallbackTracker.updateSessions(qosSessions);

        // Add filter after updateSessions
        Filter filter = new Filter(new InetSocketAddress(
                InetAddresses.parseNumericAddress("122.22.22.22"), 1357),
                new InetSocketAddress(InetAddresses.parseNumericAddress("177.77.77.77"), 3211));
        mQosCallbackTracker.addFilter(1, filter);
        processAllMessages();
        verify(mINetworkAgentRegistry, times(1)).sendEpsQosSessionAvailable(eq(1),
                any(QosSession.class), any(EpsBearerQosSessionAttributes.class));

        // Remove the matching QosBearerFilter
        qosSessions.remove(0);
        mQosCallbackTracker.updateSessions(qosSessions);
        processAllMessages();
        verify(mINetworkAgentRegistry, times(1)).sendQosSessionLost(eq(1), any(QosSession.class));
    }

    @Test
    public void testQosMetrics() {
        final int callbackId = 1;