ns-allinone-2.35/ns-2.35/dccp/dccp.cc
int DCCPAgent::setFeature(u_int8_t num, dccp_feature_location location,
	       u_char* data, u_int8_t size, bool testSet){
	u_int16_t ui16;
	
	switch(num){
	case DCCP_FEAT_CC:
		if (size == 1){
			if (ccid_ == data[0])
				return DCCP_FEAT_OK;
			else
				return DCCP_FEAT_NOT_PREFERED;
		} else
			return DCCP_FEAT_ERR_SIZE;
		break;
	case DCCP_FEAT_ECN:
		if (size == 1){
			if (location == DCCP_FEAT_LOC_LOCAL){
				if (use_ecn_local_ && data[0] ||
				    !(use_ecn_local_ || data[0]))
					return DCCP_FEAT_OK;
				else
					return DCCP_FEAT_NOT_PREFERED;
			
			} else {
				if (use_ecn_remote_ && data[0] ||
				    !(use_ecn_remote_ || data[0]))
					return DCCP_FEAT_OK;
				else
					return DCCP_FEAT_NOT_PREFERED;
			}	
		} else
			return DCCP_FEAT_ERR_SIZE;
		break;
	case DCCP_FEAT_ACK_RATIO:
		if (size == 2){
			((u_char*) &ui16)[0] = data[0];
			((u_char*) &ui16)[1] = data[1];
			if (testSet){
				if (location == DCCP_FEAT_LOC_LOCAL){
					return ((ack_ratio_local_ != (u_int16_t) ui16) ? DCCP_FEAT_ERR_TEST : DCCP_FEAT_OK);
				} else {
					return ((ack_ratio_remote_ != (u_int16_t) ui16) ? DCCP_FEAT_ERR_TEST : DCCP_FEAT_OK);
				}
			} else {
				if (location == DCCP_FEAT_LOC_LOCAL){
					ack_ratio_local_ = (u_int16_t) ui16;
					
				} else
					ack_ratio_remote_ = (u_int16_t) ui16;
			}
			return DCCP_FEAT_OK;
		} else
			return DCCP_FEAT_ERR_SIZE;
		break;
	case DCCP_FEAT_ACKV:
		if (size == 1){
			if (location == DCCP_FEAT_LOC_LOCAL){
				if (use_ackv_local_ && data[0] ||
				    !(use_ackv_local_ || data[0]))
					return DCCP_FEAT_OK;
				else
					return DCCP_FEAT_NOT_PREFERED;
			
			} else {
				if (use_ackv_remote_ == data[0]||
				    !(use_ackv_remote_ || data[0]))
					return DCCP_FEAT_OK;
				else
					return DCCP_FEAT_NOT_PREFERED;
			}
		} else
			return DCCP_FEAT_ERR_SIZE;
		break;
	case DCCP_FEAT_Q_SCHEME:
		if (size == 1){
			if (q_scheme_ == data[0])
				return DCCP_FEAT_OK;
			else
				return DCCP_FEAT_NOT_PREFERED;
		} else
			return DCCP_FEAT_ERR_SIZE;
		break;
	case DCCP_FEAT_Q:
		if (size == 1){
			if (location == DCCP_FEAT_LOC_LOCAL){
				q_local_ = (data[0] > 0 ? 1 : 0);
			} else {
				q_remote_ = (data[0] > 0 ? 1 : 0);
			}
			return DCCP_FEAT_OK;
		} else
			return DCCP_FEAT_ERR_SIZE;
		break;
	default:
		return DCCP_FEAT_UNKNOWN;
	}
}
/* Set a value for a specific feature.
 * arg: num      - feature number
 *      location - feature location
 *      data     - feature data
 *      size     - size of data
 *      testSet  - if true, only check value for correctness, don't set
 * ret: DCCP_FEAT_OK  if successful
 *      DCCP_FEAT_UNKNOWN  if the feature number is unknown
 *      DCCP_FEAT_NOT_PREFERED  if the value is not prefered
 *      DCCP_FEAT_ERR_SIZE  if the size does not match the feature
 *      DCCP_FEAT_ERR_TEST  if a non-neg feature failed the test.
 *                          a negotiable feature that fails returns NOT_PREFERED
 * Note: DCCP_FEAT_NOT_PREFERED is not applicable for non neg features.
 *       NOT_PREFERED and ERR_SIZE will trigger a reset
 */
Set a value for a specific feature.
Set a value for a specific feature .
int DCCPAgent::setFeature(u_int8_t num, dccp_feature_location location,
	       u_char* data, u_int8_t size, bool testSet){
	u_int16_t ui16;
	switch(num){
	case DCCP_FEAT_CC:
		if (size == 1){
			if (ccid_ == data[0])
				return DCCP_FEAT_OK;
			else
				return DCCP_FEAT_NOT_PREFERED;
		} else
			return DCCP_FEAT_ERR_SIZE;
		break;
	case DCCP_FEAT_ECN:
		if (size == 1){
			if (location == DCCP_FEAT_LOC_LOCAL){
				if (use_ecn_local_ && data[0] ||
				    !(use_ecn_local_ || data[0]))
					return DCCP_FEAT_OK;
				else
					return DCCP_FEAT_NOT_PREFERED;
			} else {
				if (use_ecn_remote_ && data[0] ||
				    !(use_ecn_remote_ || data[0]))
					return DCCP_FEAT_OK;
				else
					return DCCP_FEAT_NOT_PREFERED;
			}	
		} else
			return DCCP_FEAT_ERR_SIZE;
		break;
	case DCCP_FEAT_ACK_RATIO:
		if (size == 2){
			((u_char*) &ui16)[0] = data[0];
			((u_char*) &ui16)[1] = data[1];
			if (testSet){
				if (location == DCCP_FEAT_LOC_LOCAL){
					return ((ack_ratio_local_ != (u_int16_t) ui16) ? DCCP_FEAT_ERR_TEST : DCCP_FEAT_OK);
				} else {
					return ((ack_ratio_remote_ != (u_int16_t) ui16) ? DCCP_FEAT_ERR_TEST : DCCP_FEAT_OK);
				}
			} else {
				if (location == DCCP_FEAT_LOC_LOCAL){
					ack_ratio_local_ = (u_int16_t) ui16;
				} else
					ack_ratio_remote_ = (u_int16_t) ui16;
			}
			return DCCP_FEAT_OK;
		} else
			return DCCP_FEAT_ERR_SIZE;
		break;
	case DCCP_FEAT_ACKV:
		if (size == 1){
			if (location == DCCP_FEAT_LOC_LOCAL){
				if (use_ackv_local_ && data[0] ||
				    !(use_ackv_local_ || data[0]))
					return DCCP_FEAT_OK;
				else
					return DCCP_FEAT_NOT_PREFERED;
			} else {
				if (use_ackv_remote_ == data[0]||
				    !(use_ackv_remote_ || data[0]))
					return DCCP_FEAT_OK;
				else
					return DCCP_FEAT_NOT_PREFERED;
			}
		} else
			return DCCP_FEAT_ERR_SIZE;
		break;
	case DCCP_FEAT_Q_SCHEME:
		if (size == 1){
			if (q_scheme_ == data[0])
				return DCCP_FEAT_OK;
			else
				return DCCP_FEAT_NOT_PREFERED;
		} else
			return DCCP_FEAT_ERR_SIZE;
		break;
	case DCCP_FEAT_Q:
		if (size == 1){
			if (location == DCCP_FEAT_LOC_LOCAL){
				q_local_ = (data[0] > 0 ? 1 : 0);
			} else {
				q_remote_ = (data[0] > 0 ? 1 : 0);
			}
			return DCCP_FEAT_OK;
		} else
			return DCCP_FEAT_ERR_SIZE;
		break;
	default:
		return DCCP_FEAT_UNKNOWN;
	}
}
int DCCPAgent :: setFeature ( u_int8_t num , dccp_feature_location location , u_char * data , u_int8_t size , bool testSet ) { u_int16_t ui16 ; switch ( num ) { case DCCP_FEAT_CC : if ( size == 1 ) { if ( ccid_ == data [ 0 ] ) return DCCP_FEAT_OK ; else return DCCP_FEAT_NOT_PREFERED ; } else return DCCP_FEAT_ERR_SIZE ; break ; case DCCP_FEAT_ECN : if ( size == 1 ) { if ( location == DCCP_FEAT_LOC_LOCAL ) { if ( use_ecn_local_ && data [ 0 ] || ! ( use_ecn_local_ || data [ 0 ] ) ) return DCCP_FEAT_OK ; else return DCCP_FEAT_NOT_PREFERED ; } else { if ( use_ecn_remote_ && data [ 0 ] || ! ( use_ecn_remote_ || data [ 0 ] ) ) return DCCP_FEAT_OK ; else return DCCP_FEAT_NOT_PREFERED ; } } else return DCCP_FEAT_ERR_SIZE ; break ; case DCCP_FEAT_ACK_RATIO : if ( size == 2 ) { ( ( u_char * ) & ui16 ) [ 0 ] = data [ 0 ] ; ( ( u_char * ) & ui16 ) [ 1 ] = data [ 1 ] ; if ( testSet ) { if ( location == DCCP_FEAT_LOC_LOCAL ) { return ( ( ack_ratio_local_ != ( u_int16_t ) ui16 ) ? DCCP_FEAT_ERR_TEST : DCCP_FEAT_OK ) ; } else { return ( ( ack_ratio_remote_ != ( u_int16_t ) ui16 ) ? DCCP_FEAT_ERR_TEST : DCCP_FEAT_OK ) ; } } else { if ( location == DCCP_FEAT_LOC_LOCAL ) { ack_ratio_local_ = ( u_int16_t ) ui16 ; } else ack_ratio_remote_ = ( u_int16_t ) ui16 ; } return DCCP_FEAT_OK ; } else return DCCP_FEAT_ERR_SIZE ; break ; case DCCP_FEAT_ACKV : if ( size == 1 ) { if ( location == DCCP_FEAT_LOC_LOCAL ) { if ( use_ackv_local_ && data [ 0 ] || ! ( use_ackv_local_ || data [ 0 ] ) ) return DCCP_FEAT_OK ; else return DCCP_FEAT_NOT_PREFERED ; } else { if ( use_ackv_remote_ == data [ 0 ] || ! ( use_ackv_remote_ || data [ 0 ] ) ) return DCCP_FEAT_OK ; else return DCCP_FEAT_NOT_PREFERED ; } } else return DCCP_FEAT_ERR_SIZE ; break ; case DCCP_FEAT_Q_SCHEME : if ( size == 1 ) { if ( q_scheme_ == data [ 0 ] ) return DCCP_FEAT_OK ; else return DCCP_FEAT_NOT_PREFERED ; } else return DCCP_FEAT_ERR_SIZE ; break ; case DCCP_FEAT_Q : if ( size == 1 ) { if ( location == DCCP_FEAT_LOC_LOCAL ) { q_local_ = ( data [ 0 ] > 0 ? 1 : 0 ) ; } else { q_remote_ = ( data [ 0 ] > 0 ? 1 : 0 ) ; } return DCCP_FEAT_OK ; } else return DCCP_FEAT_ERR_SIZE ; break ; default : return DCCP_FEAT_UNKNOWN ; } }
Set a value for a specific feature.
Set a value for a specific feature .