[asterisk-commits] crichter: branch 1.2 r63402 - in /branches/1.2/channels: ./ misdn/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue May 8 08:07:38 MST 2007


Author: crichter
Date: Tue May  8 10:07:37 2007
New Revision: 63402

URL: http://svn.digium.com/view/asterisk?view=rev&rev=63402
Log:
added application misdn_check_l2l1 which tries to pull up the L1/L2 on all ports that have the layers down in a group. It waits then for a timeout. This helps for scenarios where multiple PMP BRIs are grouped together, or where a provider has a faulty PTP Implementation, that looses the L2 after a while.

Modified:
    branches/1.2/channels/chan_misdn.c
    branches/1.2/channels/misdn/isdn_lib.c

Modified: branches/1.2/channels/chan_misdn.c
URL: http://svn.digium.com/view/asterisk/branches/1.2/channels/chan_misdn.c?view=diff&rev=63402&r1=63401&r2=63402
==============================================================================
--- branches/1.2/channels/chan_misdn.c (original)
+++ branches/1.2/channels/chan_misdn.c Tue May  8 10:07:37 2007
@@ -320,6 +320,7 @@
 static int stop_bc_tones(struct chan_list *cl);
 static void release_chan(struct misdn_bchannel *bc);
 
+static int misdn_check_l2l1(struct ast_channel *chan, void *data);
 static int misdn_set_opt_exec(struct ast_channel *chan, void *data);
 static int misdn_facility_exec(struct ast_channel *chan, void *data);
 
@@ -2684,8 +2685,6 @@
 				}
 			} while (!newbc && robin_channel != rr->channel);
 			
-			if (!newbc)
-				chan_misdn_log(-1, port, " Failed! No free channel in group %d!", group);
 		} else {		
 			for (port=misdn_cfg_get_next_port(0); port > 0;
 				 port=misdn_cfg_get_next_port(port)) {
@@ -2709,16 +2708,27 @@
 				}
 			}
 		}
-	} else {
+		
+		/* Group dial failed ?*/
+		if (!newbc) {
+			ast_log(LOG_WARNING, 
+					"Could not Dial out on group '%s'.\n"
+					"\tEither the L2 and L1 on all of these ports where DOWN (see 'show application misdn_check_l2l1')\n"
+					"\tOr there was no free channel on none of the ports\n\n"
+					, group);
+			return NULL;
+		}
+	} else { /* 'Normal' Port dial * Port dial */
 		if (channel)
 			chan_misdn_log(1, port," --> preselected_channel: %d\n",channel);
 		newbc = misdn_lib_get_free_bc(port, channel, 0, dec);
-	}
-	
-	if (!newbc) {
-		chan_misdn_log(-1, 0, "Could not create channel on port:%d with extensions:%s\n",port,ext);
-		return NULL;
-	}
+
+		if (!newbc) {
+			ast_log(LOG_WARNING, "Could not create channel on port:%d with extensions:%s\n",port,ext);
+			return NULL;
+		}
+	}
+	
 
 	/* create ast_channel and link all the objects together */
 	cl->bc=newbc;
@@ -4396,6 +4406,24 @@
 		);
 
 
+	ast_register_application("misdn_check_l2l1", misdn_check_l2l1, "misdn_check_l2l1",
+				 "misdn_check_l2l1(<port>||g:<groupname>,timeout)"
+				 "Checks if the L2 and L1 are up on either the given <port> or\n"
+				 "on the ports in the group with <groupname>\n"
+				 "If the L1/L2 are down, check_l2l1 gets up the L1/L2 and waits\n"
+				 "for <timeout> seconds that this happens. Otherwise, nothing happens\n"
+				 "\n"
+				 "This application, ensures the L1/L2 state of the Ports in a group\n"
+				 "it is intended to make the pmp_l1_check option redundant and to\n"
+				 "fix a buggy switch config from your provider\n"
+				 "\n"
+				 "a sample dialplan would look like:\n\n"
+				 "exten => _X.,1,misdn_check_l2l1(g:out|2)\n"
+				 "exten => _X.,n,dial(mISDN/g:out/${EXTEN})\n"
+				 "\n"
+		);
+
+
 	misdn_cfg_get( 0, MISDN_GEN_TRACEFILE, global_tracefile, BUFFERSIZE);
 
 	chan_misdn_log(0, 0, "-- mISDN Channel Driver Registred -- (BE AWARE THIS DRIVER IS EXPERIMENTAL!)\n");
@@ -4438,6 +4466,7 @@
 	/* ast_unregister_application("misdn_crypt"); */
 	ast_unregister_application("misdn_set_opt");
 	ast_unregister_application("misdn_facility");
+	ast_unregister_application("misdn_check_l2l1");
   
 	ast_channel_unregister(&misdn_tech);
 
@@ -4526,6 +4555,86 @@
 	
 }
 
+static int misdn_check_l2l1(struct ast_channel *chan, void *data)
+{
+	if (strcasecmp(chan->tech->type,"mISDN")) {
+		ast_log(LOG_WARNING, "misdn_check_l2l1 makes only sense with chan_misdn channels!\n");
+		return -1;
+	}
+
+	AST_DECLARE_APP_ARGS(args,
+			AST_APP_ARG(grouppar);
+			AST_APP_ARG(timeout);
+	);
+
+	if (ast_strlen_zero((char *)data)) {
+		ast_log(LOG_WARNING, "misdn_check_l2l1 Requires arguments\n");
+		return -1;
+	}
+
+	AST_STANDARD_APP_ARGS(args, data);
+
+	if (args.argc != 2) {
+		ast_log(LOG_WARNING, "Wrong argument count\n");
+		return 0;
+	}
+
+	/*ast_log(LOG_NOTICE, "Arguments: group/port '%s' timeout '%s'\n", args.grouppar, args.timeout);*/
+	char group[BUFFERSIZE+1];
+	char *port_str;
+
+	int port=0;
+	int timeout=atoi(args.timeout);
+	int dowait=0;
+
+	port_str=args.grouppar;
+
+	int port_up;
+	if (port_str[0]=='g' && port_str[1]==':' ) {
+		/* We make a group call lets checkout which ports are in my group */
+		port_str += 2;
+		strncpy(group, port_str, BUFFERSIZE);
+		group[BUFFERSIZE-1] = 0;
+		chan_misdn_log(2, 0, "Checking Ports in group: %s\n",group);
+
+		for (	port = misdn_cfg_get_next_port(port); 
+			port > 0;
+			port = misdn_cfg_get_next_port(port)) {
+			
+			chan_misdn_log(2,0,"trying port %d\n",port);
+
+			char cfg_group[BUFFERSIZE+1];
+			misdn_cfg_get(port, MISDN_CFG_GROUPNAME, cfg_group, BUFFERSIZE);
+
+			if (!strcasecmp(cfg_group, group)) {
+				port_up = misdn_lib_port_up(port, 1);
+
+				if (!port_up) {
+					chan_misdn_log(2, 0, " --> port '%d'\n", port);
+					misdn_lib_get_port_up(port);
+					dowait=1;
+				}
+			}
+		}
+
+	} else {
+		port = atoi(port_str);
+		chan_misdn_log(2, 0, "Checking Port: %d\n",port);
+		port_up = misdn_lib_port_up(port, 1);
+		if (!port_up) {
+			misdn_lib_get_port_up(port);
+			dowait=1;
+		}
+
+	}
+
+	if (dowait) {
+		chan_misdn_log(2, 0, "Waiting for '%d' seconds\n",timeout);
+		sleep(timeout);
+	}
+
+	return 0;
+}
 
 static int misdn_set_opt_exec(struct ast_channel *chan, void *data)
 {

Modified: branches/1.2/channels/misdn/isdn_lib.c
URL: http://svn.digium.com/view/asterisk/branches/1.2/channels/misdn/isdn_lib.c?view=diff&rev=63402&r1=63401&r2=63402
==============================================================================
--- branches/1.2/channels/misdn/isdn_lib.c (original)
+++ branches/1.2/channels/misdn/isdn_lib.c Tue May  8 10:07:37 2007
@@ -15,6 +15,9 @@
 #include <syslog.h>
 #include "isdn_lib_intern.h"
 #include <mISDNuser/isdn_debug.h>
+
+
+int cfg_remember_l1=0;
 
 void misdn_join_conf(struct misdn_bchannel *bc, int conf_id);
 void misdn_split_conf(struct misdn_bchannel *bc, int conf_id);
@@ -1318,7 +1321,7 @@
 #endif
 		misdn_lib_get_short_status(stack);
 		misdn_lib_get_l1_up(stack);
-		misdn_lib_get_l2_up(stack);
+		misdn_lib_get_l2_up(stack); 
 	}
 
 	cb_log(8,0,"stack_init: port:%d lowerId:%x  upperId:%x\n",stack->port,stack->lower_id, stack->upper_id);
@@ -1711,7 +1714,7 @@
 				if (stack->l1link && stack->l2link) {
 					return 1;
 				} else {
-					cb_log(0,port, "Port Down L2:%d L1:%d\n",
+					cb_log(1,port, "Port Down L2:%d L1:%d\n",
 						stack->l2link, stack->l1link);
 					return 0;
 				}
@@ -1719,7 +1722,7 @@
 				if ( !check || stack->l1link )
 					return 1;
 				else {
-					cb_log(0,port, "Port down PMP\n");
+					cb_log(1,port, "Port down PMP\n");
 					return 0;
 				}
 			}
@@ -2848,8 +2851,11 @@
 			/*when the L2 goes UP, L1 needs to be UP too*/
 			stack->l1link=1;
 			stack->l2link=1;
-			if ( !stack->ptp && !stack->nt )
-				stack->l1link=2;
+			
+			if (cfg_remember_l1) {
+				if ( !stack->ptp && !stack->nt )
+					stack->l1link=2;
+			}
 			break;
 			
 		case SSTATUS_L2_RELEASED:



More information about the asterisk-commits mailing list