use of com.att.aro.core.packetanalysis.pojo.DchDemotionQueue in project VideoOptimzer by attdevsupport.
the class RrcStateRangeFactoryImpl method create3G.
/**
* This method contains the main algorithm for creating the List of
* RrcStateRange for a 3G profile
*
* @param analysisData
* Analysis data
* @param profile
* 3G profile
* @return list of RRC State range values.
*/
private List<RrcStateRange> create3G(List<PacketInfo> packetlist, Profile3G profile, double traceDuration) {
List<PacketInfo> packetInfos = packetlist;
List<RrcStateRange> result = new ArrayList<RrcStateRange>();
if (packetInfos != null && !packetInfos.isEmpty()) {
// Get important profile info
double idleDchPromoAvg = profile.getIdleDchPromoAvg();
double idleDchPromoMin = profile.getIdleDchPromoMin();
double idleDchPromoMax = profile.getIdleDchPromoMax();
double fachDchPromoAvg = profile.getFachDchPromoAvg();
double fachDchPromoMin = profile.getFachDchPromoMin();
double fachDchPromoMax = profile.getFachDchPromoMax();
double dchFachTimer = profile.getDchFachTimer();
double fachIdleTimer = profile.getFachIdleTimer();
double timer = 0;
DchDemotionQueue dchDemotionQueue = new DchDemotionQueue(profile);
FachQueue fachQueue = new FachQueue(profile);
// Set up initial packet
PacketInfo prevPacket = packetInfos.get(0);
double currTimeStamp = prevPacket.getTimeStamp();
prevPacket.setStateMachine(RRCState.PROMO_IDLE_DCH);
// Add initial idle state
addStateRangeEx(result, 0, Double.MAX_VALUE, RRCState.STATE_IDLE, currTimeStamp);
for (int i = 1; i <= packetInfos.size(); ++i) {
PacketInfo packet;
PacketDirection dir;
int currLen;
if (i >= packetInfos.size()) {
// The last iteration of this loop
packet = null;
dir = PacketDirection.UPLINK;
currTimeStamp = Double.MAX_VALUE;
currLen = 0;
} else {
// Iteration on a packet
packet = packetInfos.get(i);
dir = packet.getDir();
currTimeStamp = packet.getTimeStamp();
currLen = packet.getLen();
}
double prevTimeStamp = (prevPacket == null ? 0.0 : prevPacket.getTimeStamp());
double deltaTime = currTimeStamp - prevTimeStamp;
// the next state to be determined
RRCState state = null;
RRCState promoState = (prevPacket == null ? RRCState.STATE_IDLE : prevPacket.getStateMachine());
if (promoState == RRCState.PROMO_IDLE_DCH || promoState == RRCState.PROMO_FACH_DCH) {
double promoAvg, promoMin, promoMax;
if (promoState == RRCState.PROMO_IDLE_DCH) {
promoAvg = idleDchPromoAvg;
promoMin = idleDchPromoMin;
promoMax = idleDchPromoMax;
} else {
promoAvg = fachDchPromoAvg;
promoMin = fachDchPromoMin;
promoMax = fachDchPromoMax;
}
if (dir == PacketDirection.UPLINK && timer + deltaTime <= promoMin) {
// Case
// 1
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, Double.MAX_VALUE, promoState, currTimeStamp);
state = promoState;
timer += deltaTime;
} else if (dir == PacketDirection.DOWNLINK && timer + deltaTime <= promoMin) {
// TODO: handle an error situation here: a DOWNLINK DCH
// packet follows "immediately" after a packet on
// FACH/IDLE
// promotion
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, Double.MAX_VALUE, promoState, currTimeStamp);
state = promoState;
timer += deltaTime;
} else if (timer + deltaTime <= promoMax) {
// Case 2
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, Double.MAX_VALUE, promoState, currTimeStamp);
state = RRCState.STATE_DCH;
dchDemotionQueue.init(currTimeStamp, currLen, dir);
} else if (timer + deltaTime <= promoAvg + dchFachTimer) {
// Case
// 3
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, promoAvg - timer, promoState, currTimeStamp);
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, Double.MAX_VALUE, RRCState.STATE_DCH, currTimeStamp);
state = RRCState.STATE_DCH;
dchDemotionQueue.init(currTimeStamp, currLen, dir);
} else if (timer + deltaTime <= promoAvg + dchFachTimer + fachIdleTimer) {
// 4
if (dir == PacketDirection.DOWNLINK) {
fachQueue.init();
if (fachQueue.simFACH(currTimeStamp, dir, currLen)) {
// FACH->DCH
double tMax0 = currTimeStamp - fachDchPromoAvg;
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, promoAvg - timer, promoState, tMax0);
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, dchFachTimer, RRCState.TAIL_DCH, tMax0);
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, Double.MAX_VALUE, RRCState.STATE_FACH, tMax0);
// promoTime = tMax - tt;
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, Double.MAX_VALUE, RRCState.PROMO_FACH_DCH, currTimeStamp);
state = RRCState.STATE_DCH;
dchDemotionQueue.init(currTimeStamp, currLen, dir);
} else {
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, promoAvg - timer, promoState, currTimeStamp);
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, dchFachTimer, RRCState.TAIL_DCH, currTimeStamp);
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, Double.MAX_VALUE, RRCState.STATE_FACH, currTimeStamp);
state = RRCState.STATE_FACH;
}
} else {
// downlink
fachQueue.init();
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, promoAvg - timer, promoState, currTimeStamp);
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, dchFachTimer, RRCState.TAIL_DCH, currTimeStamp);
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, Double.MAX_VALUE, RRCState.STATE_FACH, currTimeStamp);
if (fachQueue.simFACH(currTimeStamp, dir, currLen)) {
state = RRCState.PROMO_FACH_DCH;
timer = 0;
} else {
state = RRCState.STATE_FACH;
}
}
} else {
// case 5
if (dir == PacketDirection.UPLINK) {
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, promoAvg - timer, promoState, currTimeStamp);
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, dchFachTimer, RRCState.TAIL_DCH, currTimeStamp);
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, fachIdleTimer, RRCState.TAIL_FACH, currTimeStamp);
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, Double.MAX_VALUE, RRCState.STATE_IDLE, currTimeStamp);
state = RRCState.PROMO_IDLE_DCH;
timer = 0;
} else {
// downlink
double tMax0 = currTimeStamp - idleDchPromoAvg;
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, promoAvg - timer, promoState, tMax0);
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, dchFachTimer, RRCState.TAIL_DCH, tMax0);
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, fachIdleTimer, RRCState.TAIL_FACH, tMax0);
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, Double.MAX_VALUE, RRCState.STATE_IDLE, tMax0);
// promoTime = tMax - tt;
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, Double.MAX_VALUE, RRCState.PROMO_IDLE_DCH, currTimeStamp);
state = RRCState.STATE_DCH;
dchDemotionQueue.init(currTimeStamp, currLen, dir);
}
}
// break;
} else if (promoState == RRCState.STATE_DCH) {
// ***
double dchTail = dchDemotionQueue.getDCHTail(currTimeStamp);
if (deltaTime <= dchTail + 1e-5) {
// DCH Case 1
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, Double.MAX_VALUE, RRCState.STATE_DCH, currTimeStamp);
state = RRCState.STATE_DCH;
dchDemotionQueue.update(currTimeStamp, currLen, dir);
} else if (deltaTime <= dchTail + fachIdleTimer) {
// 2
if (dir == PacketDirection.DOWNLINK) {
// downlink
fachQueue.init();
if (fachQueue.simFACH(currTimeStamp, dir, currLen)) {
double tMax0 = currTimeStamp - fachDchPromoAvg;
changeStateRangeBack(result, dchFachTimer - dchTail, RRCState.TAIL_DCH);
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, dchTail, RRCState.TAIL_DCH, tMax0);
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, Double.MAX_VALUE, RRCState.STATE_FACH, tMax0);
// promoTime = tMax - tt;
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, Double.MAX_VALUE, RRCState.PROMO_FACH_DCH, currTimeStamp);
state = RRCState.STATE_DCH;
dchDemotionQueue.init(currTimeStamp, currLen, dir);
} else {
changeStateRangeBack(result, dchFachTimer - dchTail, RRCState.TAIL_DCH);
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, dchTail, RRCState.TAIL_DCH, currTimeStamp);
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, Double.MAX_VALUE, RRCState.STATE_FACH, currTimeStamp);
state = RRCState.STATE_FACH;
}
} else {
// uplink
fachQueue.init();
changeStateRangeBack(result, dchFachTimer - dchTail, RRCState.TAIL_DCH);
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, dchTail, RRCState.TAIL_DCH, currTimeStamp);
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, Double.MAX_VALUE, RRCState.STATE_FACH, currTimeStamp);
if (fachQueue.simFACH(currTimeStamp, dir, currLen)) {
state = RRCState.PROMO_FACH_DCH;
timer = 0;
} else {
state = RRCState.STATE_FACH;
}
}
} else {
// DCH Case 3
if (dir == PacketDirection.UPLINK) {
// uplink
changeStateRangeBack(result, dchFachTimer - dchTail, RRCState.TAIL_DCH);
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, dchTail, RRCState.TAIL_DCH, currTimeStamp);
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, fachIdleTimer, RRCState.TAIL_FACH, currTimeStamp);
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, Double.MAX_VALUE, RRCState.STATE_IDLE, currTimeStamp);
state = RRCState.PROMO_IDLE_DCH;
timer = 0;
} else {
// downlink
double tMax0 = currTimeStamp - idleDchPromoAvg;
changeStateRangeBack(result, dchFachTimer - dchTail, RRCState.TAIL_DCH);
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, dchTail, RRCState.TAIL_DCH, tMax0);
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, fachIdleTimer, RRCState.TAIL_FACH, tMax0);
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, Double.MAX_VALUE, RRCState.STATE_IDLE, tMax0);
// promoTime = tMax - tt;
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, Double.MAX_VALUE, RRCState.PROMO_IDLE_DCH, currTimeStamp);
state = RRCState.STATE_DCH;
dchDemotionQueue.init(currTimeStamp, currLen, dir);
}
}
// break;
} else if (promoState == RRCState.STATE_FACH) {
if (deltaTime <= fachIdleTimer) {
if (dir == PacketDirection.UPLINK) {
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, Double.MAX_VALUE, RRCState.STATE_FACH, currTimeStamp);
if (fachQueue.simFACH(currTimeStamp, dir, currLen)) {
state = RRCState.PROMO_FACH_DCH;
timer = 0;
} else {
state = RRCState.STATE_FACH;
}
} else {
// downlink
if (fachQueue.simFACH(currTimeStamp, dir, currLen)) {
double tMax0 = currTimeStamp - fachDchPromoAvg;
/*
* TODO: ( diff ) handle the case where promo
* delay is 0 ( for what - if )
*/
if (tMax0 > prevTimeStamp || fachDchPromoAvg < 1e-6) {
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, Double.MAX_VALUE, RRCState.STATE_FACH, tMax0);
// promoTime = tMax - tt;
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, Double.MAX_VALUE, RRCState.PROMO_FACH_DCH, currTimeStamp);
} else {
// *** handle an error situation here: a
// DOWNLINK DCH packet follows "immediately"
// after a packet on FACH
// try
tMax0 = currTimeStamp - fachDchPromoMin;
// y?
if (tMax0 > prevTimeStamp) {
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, Double.MAX_VALUE, RRCState.STATE_FACH, tMax0);
// promoTime = tMax - tt;
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, Double.MAX_VALUE, RRCState.PROMO_FACH_DCH, currTimeStamp);
} else {
// still not working - try to
// insert a
// promotion after some previous
// packet
boolean bFixed = false;
for (int ii = i - 1; ii > 0; ii--) {
PacketInfo earlierPacket = packetInfos.get(ii);
if (earlierPacket.getStateMachine() == RRCState.STATE_FACH) {
// FACH-DCH promo: from
// packets[ii].ts to
// packets[ii].ts+y
// DCH: from packets[ii].ts+y to
// tMax
double piTimeStamp = packetInfos.get(ii).getTimeStamp();
if (earlierPacket.getDir() == PacketDirection.UPLINK && currTimeStamp >= piTimeStamp + fachDchPromoMin) {
int resultSize = result.size() - 1;
// boolean bDone = false;
for (int jj = resultSize; jj > 0; jj--) {
// double EPS = 1e-4;
if (result.get(jj).getBeginTime() == piTimeStamp) {
for (int k = 0; k < resultSize - jj + 1; k++) {
result.remove(result.size() - 1);
}
double avgDchPromo;
if (currTimeStamp >= piTimeStamp + fachDchPromoAvg) {
avgDchPromo = fachDchPromoAvg;
} else {
avgDchPromo = fachDchPromoMin;
}
result.add(new RrcStateRange(piTimeStamp, piTimeStamp + avgDchPromo, RRCState.PROMO_FACH_DCH));
result.add(new RrcStateRange(piTimeStamp + avgDchPromo, prevTimeStamp, RRCState.STATE_DCH));
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, Double.MAX_VALUE, RRCState.STATE_DCH, currTimeStamp);
break;
}
// #undef EPS
}
bFixed = true;
break;
}
} else {
break;
}
}
if (!bFixed) {
// still not working - force it on
// FACH
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, Double.MAX_VALUE, RRCState.STATE_FACH, currTimeStamp);
state = RRCState.STATE_FACH;
fachQueue.init();
}
}
}
// finish handling the error case
state = RRCState.STATE_DCH;
dchDemotionQueue.init(currTimeStamp, currLen, dir);
} else {
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, Double.MAX_VALUE, RRCState.STATE_FACH, currTimeStamp);
state = RRCState.STATE_FACH;
}
}
} else {
if (dir == PacketDirection.UPLINK) {
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, fachIdleTimer, RRCState.TAIL_FACH, currTimeStamp);
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, Double.MAX_VALUE, RRCState.STATE_IDLE, currTimeStamp);
state = RRCState.PROMO_IDLE_DCH;
timer = 0;
} else {
// downlink
double tMax0 = currTimeStamp - idleDchPromoAvg;
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, fachIdleTimer, RRCState.TAIL_FACH, tMax0);
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, Double.MAX_VALUE, RRCState.STATE_IDLE, tMax0);
// promoTime = tMax - tt;
prevTimeStamp = addStateRangeEx(result, prevTimeStamp, Double.MAX_VALUE, RRCState.PROMO_IDLE_DCH, currTimeStamp);
state = RRCState.STATE_DCH;
dchDemotionQueue.init(currTimeStamp, currLen, dir);
}
}
}
if (packet != null) {
packet.setStateMachine(state);
}
prevPacket = packet;
}
}
result = compressStateRanges(result);
// Truncate state ranges at end of trace
Iterator<RrcStateRange> iter = result.iterator();
double prevTimeStamp = 0.0;
while (iter.hasNext()) {
RrcStateRange rrc = iter.next();
if (rrc.getBeginTime() >= traceDuration) {
iter.remove();
}
if (rrc.getEndTime() > traceDuration) {
rrc.setEndTime(traceDuration);
}
prevTimeStamp = rrc.getEndTime();
}
if (prevTimeStamp < traceDuration) {
// Add idle time to end of trace
result.add(new RrcStateRange(prevTimeStamp, traceDuration, RRCState.STATE_IDLE));
}
return result;
}
Aggregations