#818 Resolves P25 duplicate traffic channel issue where duplicate traffic channels were being allocated for the same frequency. (#834)

Co-authored-by: Denny <denny@denny-desktop>
This commit is contained in:
Denny Sheirer
2020-05-25 06:29:56 -04:00
committed by GitHub
parent 2bb5082943
commit ad194d1bab

View File

@@ -67,7 +67,6 @@ import java.util.Objects;
import java.util.Queue; import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.function.Consumer;
/** /**
* Monitors channel grant and channel grant update messages to allocate traffic channels to capture * Monitors channel grant and channel grant update messages to allocate traffic channels to capture
@@ -98,10 +97,9 @@ public class P25TrafficChannelManager extends Module implements IDecodeEventProv
private Queue<Channel> mAvailablePhase2TrafficChannelQueue = new ConcurrentLinkedQueue<>(); private Queue<Channel> mAvailablePhase2TrafficChannelQueue = new ConcurrentLinkedQueue<>();
private List<Channel> mManagedPhase2TrafficChannels; private List<Channel> mManagedPhase2TrafficChannels;
private Map<APCO25Channel,Channel> mAllocatedTrafficChannelMap = new ConcurrentHashMap<>(); private Map<Long,Channel> mAllocatedTrafficChannelMap = new ConcurrentHashMap<>();
private Map<APCO25Channel,P25ChannelGrantEvent> mPhase1ChannelGrantEventMap = new ConcurrentHashMap<>(); private Map<Long,P25ChannelGrantEvent> mTS0ChannelGrantEventMap = new ConcurrentHashMap<>();
private Map<APCO25Channel,P25ChannelGrantEvent> mPhase2TS0ChannelGrantEventMap = new ConcurrentHashMap<>(); private Map<Long,P25ChannelGrantEvent> mTS1ChannelGrantEventMap = new ConcurrentHashMap<>();
private Map<APCO25Channel,P25ChannelGrantEvent> mPhase2TS1ChannelGrantEventMap = new ConcurrentHashMap<>();
private Listener<ChannelEvent> mChannelEventListener; private Listener<ChannelEvent> mChannelEventListener;
private Listener<IDecodeEvent> mDecodeEventListener; private Listener<IDecodeEvent> mDecodeEventListener;
@@ -114,10 +112,7 @@ public class P25TrafficChannelManager extends Module implements IDecodeEventProv
private boolean mIgnoreDataCalls; private boolean mIgnoreDataCalls;
/** /**
* Monitors call events and allocates traffic decoder channels in response * Constructs an instance.
* to traffic channel allocation call events. Manages a pool of reusable
* traffic channel allocations.
*
* @param parentChannel that owns this traffic channel manager * @param parentChannel that owns this traffic channel manager
*/ */
public P25TrafficChannelManager(Channel parentChannel) public P25TrafficChannelManager(Channel parentChannel)
@@ -273,8 +268,9 @@ public class P25TrafficChannelManager extends Module implements IDecodeEventProv
private void processPhase1ChannelGrant(APCO25Channel apco25Channel, ServiceOptions serviceOptions, private void processPhase1ChannelGrant(APCO25Channel apco25Channel, ServiceOptions serviceOptions,
IdentifierCollection identifierCollection, Opcode opcode, long timestamp) IdentifierCollection identifierCollection, Opcode opcode, long timestamp)
{ {
long frequency = apco25Channel.getDownlinkFrequency();
P25ChannelGrantEvent event = mPhase1ChannelGrantEventMap.get(apco25Channel); P25ChannelGrantEvent event = mTS0ChannelGrantEventMap.get(frequency);
if(event != null && isSameCall(identifierCollection, event.getIdentifierCollection())) if(event != null && isSameCall(identifierCollection, event.getIdentifierCollection()))
{ {
@@ -294,7 +290,7 @@ public class P25TrafficChannelManager extends Module implements IDecodeEventProv
.identifiers(identifierCollection) .identifiers(identifierCollection)
.build(); .build();
mPhase1ChannelGrantEventMap.put(apco25Channel, continuationGrantEvent); mTS0ChannelGrantEventMap.put(frequency, continuationGrantEvent);
broadcast(continuationGrantEvent); broadcast(continuationGrantEvent);
} }
} }
@@ -305,7 +301,7 @@ public class P25TrafficChannelManager extends Module implements IDecodeEventProv
//Even though we have an event, the initial channel grant may have been rejected. Check to see if there //Even though we have an event, the initial channel grant may have been rejected. Check to see if there
//is a traffic channel allocated. If not, allocate one and update the event description. //is a traffic channel allocated. If not, allocate one and update the event description.
if(!mAllocatedTrafficChannelMap.containsKey(apco25Channel) && !(mIgnoreDataCalls && opcode.isDataChannelGrant())) if(!mAllocatedTrafficChannelMap.containsKey(frequency) && !(mIgnoreDataCalls && opcode.isDataChannelGrant()))
{ {
Channel trafficChannel = mAvailablePhase1TrafficChannelQueue.poll(); Channel trafficChannel = mAvailablePhase1TrafficChannelQueue.poll();
@@ -316,9 +312,9 @@ public class P25TrafficChannelManager extends Module implements IDecodeEventProv
event.setChannelDescriptor(apco25Channel); event.setChannelDescriptor(apco25Channel);
broadcast(event); broadcast(event);
SourceConfigTuner sourceConfig = new SourceConfigTuner(); SourceConfigTuner sourceConfig = new SourceConfigTuner();
sourceConfig.setFrequency(apco25Channel.getDownlinkFrequency()); sourceConfig.setFrequency(frequency);
trafficChannel.setSourceConfiguration(sourceConfig); trafficChannel.setSourceConfiguration(sourceConfig);
mAllocatedTrafficChannelMap.put(apco25Channel, trafficChannel); mAllocatedTrafficChannelMap.put(frequency, trafficChannel);
broadcast(new ChannelGrantEvent(trafficChannel, Event.REQUEST_ENABLE, apco25Channel, identifierCollection)); broadcast(new ChannelGrantEvent(trafficChannel, Event.REQUEST_ENABLE, apco25Channel, identifierCollection));
} }
} }
@@ -335,8 +331,7 @@ public class P25TrafficChannelManager extends Module implements IDecodeEventProv
.identifiers(identifierCollection) .identifiers(identifierCollection)
.build(); .build();
mPhase1ChannelGrantEventMap.put(apco25Channel, channelGrantEvent); mTS0ChannelGrantEventMap.put(frequency, channelGrantEvent);
broadcast(channelGrantEvent); broadcast(channelGrantEvent);
return; return;
} }
@@ -348,11 +343,10 @@ public class P25TrafficChannelManager extends Module implements IDecodeEventProv
.identifiers(identifierCollection) .identifiers(identifierCollection)
.build(); .build();
mPhase1ChannelGrantEventMap.put(apco25Channel, channelGrantEvent); mTS0ChannelGrantEventMap.put(frequency, channelGrantEvent);
//Allocate a traffic channel for the downlink frequency if one isn't already allocated //Allocate a traffic channel for the downlink frequency if one isn't already allocated
//NOTE: we could also allocate a traffic channel for the uplink frequency here, in the future if(!mAllocatedTrafficChannelMap.containsKey(frequency))
if(!mAllocatedTrafficChannelMap.containsKey(apco25Channel))
{ {
Channel trafficChannel = mAvailablePhase1TrafficChannelQueue.poll(); Channel trafficChannel = mAvailablePhase1TrafficChannelQueue.poll();
@@ -364,9 +358,9 @@ public class P25TrafficChannelManager extends Module implements IDecodeEventProv
} }
SourceConfigTuner sourceConfig = new SourceConfigTuner(); SourceConfigTuner sourceConfig = new SourceConfigTuner();
sourceConfig.setFrequency(apco25Channel.getDownlinkFrequency()); sourceConfig.setFrequency(frequency);
trafficChannel.setSourceConfiguration(sourceConfig); trafficChannel.setSourceConfiguration(sourceConfig);
mAllocatedTrafficChannelMap.put(apco25Channel, trafficChannel); mAllocatedTrafficChannelMap.put(frequency, trafficChannel);
broadcast(new ChannelGrantEvent(trafficChannel, Event.REQUEST_ENABLE, apco25Channel, identifierCollection)); broadcast(new ChannelGrantEvent(trafficChannel, Event.REQUEST_ENABLE, apco25Channel, identifierCollection));
} }
@@ -392,16 +386,17 @@ public class P25TrafficChannelManager extends Module implements IDecodeEventProv
} }
int timeslot = apco25Channel.getTimeslot(); int timeslot = apco25Channel.getTimeslot();
long frequency = apco25Channel.getDownlinkFrequency();
P25ChannelGrantEvent event = null; P25ChannelGrantEvent event = null;
if(timeslot == 0) if(timeslot == 0)
{ {
event = mPhase2TS0ChannelGrantEventMap.get(apco25Channel); event = mTS0ChannelGrantEventMap.get(frequency);
} }
else if(timeslot == 1) else if(timeslot == 1)
{ {
event = mPhase2TS1ChannelGrantEventMap.get(apco25Channel); event = mTS1ChannelGrantEventMap.get(frequency);
} }
else else
{ {
@@ -431,11 +426,11 @@ public class P25TrafficChannelManager extends Module implements IDecodeEventProv
if(timeslot == 0) if(timeslot == 0)
{ {
mPhase2TS0ChannelGrantEventMap.put(apco25Channel, continuationGrantEvent); mTS0ChannelGrantEventMap.put(frequency, continuationGrantEvent);
} }
else else
{ {
mPhase2TS1ChannelGrantEventMap.put(apco25Channel, continuationGrantEvent); mTS1ChannelGrantEventMap.put(frequency, continuationGrantEvent);
} }
broadcast(continuationGrantEvent); broadcast(continuationGrantEvent);
@@ -448,8 +443,7 @@ public class P25TrafficChannelManager extends Module implements IDecodeEventProv
//Even though we have an event, the initial channel grant may have been rejected. Check to see if there //Even though we have an event, the initial channel grant may have been rejected. Check to see if there
//is a traffic channel allocated. If not, allocate one and update the event description. //is a traffic channel allocated. If not, allocate one and update the event description.
if(!mAllocatedTrafficChannelMap.containsKey(apco25Channel) && if(!mAllocatedTrafficChannelMap.containsKey(frequency) && !(mIgnoreDataCalls && opcode.isDataChannelGrant()))
!(mIgnoreDataCalls && opcode.isDataChannelGrant()))
{ {
Channel trafficChannel = mAvailablePhase2TrafficChannelQueue.poll(); Channel trafficChannel = mAvailablePhase2TrafficChannelQueue.poll();
@@ -460,9 +454,9 @@ public class P25TrafficChannelManager extends Module implements IDecodeEventProv
event.setChannelDescriptor(apco25Channel); event.setChannelDescriptor(apco25Channel);
broadcast(event); broadcast(event);
SourceConfigTuner sourceConfig = new SourceConfigTuner(); SourceConfigTuner sourceConfig = new SourceConfigTuner();
sourceConfig.setFrequency(apco25Channel.getDownlinkFrequency()); sourceConfig.setFrequency(frequency);
trafficChannel.setSourceConfiguration(sourceConfig); trafficChannel.setSourceConfiguration(sourceConfig);
mAllocatedTrafficChannelMap.put(apco25Channel, trafficChannel); mAllocatedTrafficChannelMap.put(frequency, trafficChannel);
//If we have valid scramble/randomizer parameters, set them in the decode config //If we have valid scramble/randomizer parameters, set them in the decode config
if(mPhase2ScrambleParameters != null) if(mPhase2ScrambleParameters != null)
@@ -487,7 +481,7 @@ public class P25TrafficChannelManager extends Module implements IDecodeEventProv
.identifiers(identifierCollection) .identifiers(identifierCollection)
.build(); .build();
mPhase1ChannelGrantEventMap.put(apco25Channel, channelGrantEvent); mTS0ChannelGrantEventMap.put(frequency, channelGrantEvent);
broadcast(channelGrantEvent); broadcast(channelGrantEvent);
return; return;
@@ -502,16 +496,15 @@ public class P25TrafficChannelManager extends Module implements IDecodeEventProv
if(timeslot == 0) if(timeslot == 0)
{ {
mPhase2TS0ChannelGrantEventMap.put(apco25Channel, channelGrantEvent); mTS0ChannelGrantEventMap.put(frequency, channelGrantEvent);
} }
else else
{ {
mPhase2TS1ChannelGrantEventMap.put(apco25Channel, channelGrantEvent); mTS1ChannelGrantEventMap.put(frequency, channelGrantEvent);
} }
//Allocate a traffic channel for the downlink frequency if one isn't already allocated //Allocate a traffic channel for the downlink frequency if one isn't already allocated
//NOTE: we could also allocate a traffic channel for the uplink frequency here, in the future if(!mAllocatedTrafficChannelMap.containsKey(apco25Channel.getDownlinkFrequency()))
if(!mAllocatedTrafficChannelMap.containsKey(apco25Channel))
{ {
Channel trafficChannel = mAvailablePhase2TrafficChannelQueue.poll(); Channel trafficChannel = mAvailablePhase2TrafficChannelQueue.poll();
@@ -523,9 +516,9 @@ public class P25TrafficChannelManager extends Module implements IDecodeEventProv
} }
SourceConfigTuner sourceConfig = new SourceConfigTuner(); SourceConfigTuner sourceConfig = new SourceConfigTuner();
sourceConfig.setFrequency(apco25Channel.getDownlinkFrequency()); sourceConfig.setFrequency(frequency);
trafficChannel.setSourceConfiguration(sourceConfig); trafficChannel.setSourceConfiguration(sourceConfig);
mAllocatedTrafficChannelMap.put(apco25Channel, trafficChannel); mAllocatedTrafficChannelMap.put(frequency, trafficChannel);
broadcast(new ChannelGrantEvent(trafficChannel, Event.REQUEST_ENABLE, apco25Channel, identifierCollection)); broadcast(new ChannelGrantEvent(trafficChannel, Event.REQUEST_ENABLE, apco25Channel, identifierCollection));
} }
@@ -660,6 +653,11 @@ public class P25TrafficChannelManager extends Module implements IDecodeEventProv
{ {
broadcast(new ChannelEvent(trafficChannel, Event.REQUEST_DISABLE)); broadcast(new ChannelEvent(trafficChannel, Event.REQUEST_DISABLE));
} }
for(Channel trafficChannel : mAvailablePhase2TrafficChannelQueue)
{
broadcast(new ChannelEvent(trafficChannel, Event.REQUEST_DISABLE));
}
} }
/** /**
@@ -701,6 +699,9 @@ public class P25TrafficChannelManager extends Module implements IDecodeEventProv
mLog.info("Stopping traffic channel: " + channel); mLog.info("Stopping traffic channel: " + channel);
broadcast(new ChannelEvent(channel, Event.REQUEST_DISABLE)); broadcast(new ChannelEvent(channel, Event.REQUEST_DISABLE));
} }
mTS0ChannelGrantEventMap.clear();
mTS1ChannelGrantEventMap.clear();
} }
/** /**
@@ -715,21 +716,16 @@ public class P25TrafficChannelManager extends Module implements IDecodeEventProv
{ {
if(mMessageListener == null) if(mMessageListener == null)
{ {
mMessageListener = new Listener<IMessage>() mMessageListener = message -> {
{ if(mPhase2ScrambleParameters == null && message.isValid())
@Override
public void receive(IMessage message)
{ {
if(mPhase2ScrambleParameters == null && message.isValid()) if(message instanceof NetworkStatusBroadcast)
{ {
if(message instanceof NetworkStatusBroadcast) mPhase2ScrambleParameters = ((NetworkStatusBroadcast)message).getScrambleParameters();
{ }
mPhase2ScrambleParameters = ((NetworkStatusBroadcast)message).getScrambleParameters(); else if(message instanceof AMBTCNetworkStatusBroadcast)
} {
else if(message instanceof AMBTCNetworkStatusBroadcast) mPhase2ScrambleParameters = ((AMBTCNetworkStatusBroadcast)message).getScrambleParameters();
{
mPhase2ScrambleParameters = ((AMBTCNetworkStatusBroadcast)message).getScrambleParameters();
}
} }
} }
}; };
@@ -770,24 +766,22 @@ public class P25TrafficChannelManager extends Module implements IDecodeEventProv
public class TrafficChannelTeardownMonitor implements Listener<ChannelEvent> public class TrafficChannelTeardownMonitor implements Listener<ChannelEvent>
{ {
/** /**
* Removes any call events that are associated with the specified channel. * Removes an allocated traffic channel and adds it to the available channel queue
* @param channel that was removed * @param channel to reset
* @param frequency of the channel
* @param isPhase1 true or false if it is a phase 2 channel
*/ */
private void cleanupCallEvents(Channel channel) private void resetTrafficChannel(Channel channel, long frequency, boolean isPhase1)
{ {
if(channel.getSourceConfiguration() instanceof SourceConfigTuner) mAllocatedTrafficChannelMap.remove(frequency);
{
long frequency = ((SourceConfigTuner)channel.getSourceConfiguration()).getFrequency();
if(channel.getDecodeConfiguration().getDecoderType() == DecoderType.P25_PHASE1) if(isPhase1)
{ {
mPhase1ChannelGrantEventMap.entrySet().removeIf(entry -> entry.getKey().getDownlinkFrequency() == frequency); mAvailablePhase1TrafficChannelQueue.add(channel);
} }
else else
{ {
mPhase2TS0ChannelGrantEventMap.entrySet().removeIf(entry -> entry.getKey().getDownlinkFrequency() == frequency); mAvailablePhase2TrafficChannelQueue.add(channel);
mPhase2TS1ChannelGrantEventMap.entrySet().removeIf(entry -> entry.getKey().getDownlinkFrequency() == frequency);
}
} }
} }
@@ -810,48 +804,43 @@ public class P25TrafficChannelManager extends Module implements IDecodeEventProv
.filter(entry -> entry.getValue() == channel) .filter(entry -> entry.getValue() == channel)
.map(Map.Entry::getKey) .map(Map.Entry::getKey)
.findFirst() .findFirst()
.ifPresent(toRemove -> { .ifPresent(frequencyToRemove -> {
mAllocatedTrafficChannelMap.remove(toRemove); resetTrafficChannel(channel, frequencyToRemove, isPhase1);
mTS0ChannelGrantEventMap.remove(frequencyToRemove);
if (isPhase1) { mTS1ChannelGrantEventMap.remove(frequencyToRemove);
mAvailablePhase1TrafficChannelQueue.add(channel);
} else {
mAvailablePhase2TrafficChannelQueue.add(channel);
}
}); });
cleanupCallEvents(channel);
break; break;
case NOTIFICATION_PROCESSING_START_REJECTED: case NOTIFICATION_PROCESSING_START_REJECTED:
mAllocatedTrafficChannelMap.entrySet().stream() mAllocatedTrafficChannelMap.entrySet().stream()
.filter(entry -> entry.getValue() == channel) .filter(entry -> entry.getValue() == channel)
.map(Map.Entry::getKey) .map(Map.Entry::getKey)
.findFirst() .findFirst()
.ifPresent(rejected -> { .ifPresent(rejectedFrequency -> {
mAllocatedTrafficChannelMap.remove(rejected); resetTrafficChannel(channel, rejectedFrequency, isPhase1);
if (isPhase1) { P25ChannelGrantEvent event = mTS0ChannelGrantEventMap.remove(rejectedFrequency);
mAvailablePhase1TrafficChannelQueue.add(channel);
} else { if(event == null)
mAvailablePhase2TrafficChannelQueue.add(channel); {
event = mTS1ChannelGrantEventMap.remove(rejectedFrequency);
} }
P25ChannelGrantEvent event = mPhase1ChannelGrantEventMap.get(rejected); if (event != null)
{
if (event != null) {
event.setEventDescription(event.getEventDescription() + " - Rejected"); event.setEventDescription(event.getEventDescription() + " - Rejected");
if (channelEvent.getDescription() != null) { if (channelEvent.getDescription() != null)
{
event.setDetails(channelEvent.getDescription() + " - " + event.getDetails()); event.setDetails(channelEvent.getDescription() + " - " + event.getDetails());
} else { }
else
{
event.setDetails(CHANNEL_START_REJECTED + " - " + event.getDetails()); event.setDetails(CHANNEL_START_REJECTED + " - " + event.getDetails());
} }
broadcast(event); broadcast(event);
} }
}); });
cleanupCallEvents(channel);
break; break;
} }
} }