[svn-commits] mattf: trunk r61 - in /trunk: mtp2.c mtp2.h mtp3.c mtp3.h ss7.c ss7_internal.h

svn-commits at lists.digium.com svn-commits at lists.digium.com
Wed Nov 1 15:17:01 MST 2006


Author: mattf
Date: Wed Nov  1 16:17:01 2006
New Revision: 61

URL: http://svn.digium.com/view/libss7?rev=61&view=rev
Log:
Let's do better linkstate up and down management!

Modified:
    trunk/mtp2.c
    trunk/mtp2.h
    trunk/mtp3.c
    trunk/mtp3.h
    trunk/ss7.c
    trunk/ss7_internal.h

Modified: trunk/mtp2.c
URL: http://svn.digium.com/view/libss7/trunk/mtp2.c?rev=61&r1=60&r2=61&view=diff
==============================================================================
--- trunk/mtp2.c (original)
+++ trunk/mtp2.c Wed Nov  1 16:17:01 2006
@@ -628,8 +628,9 @@
 	}
 }
 
-int mtp2_start(struct mtp2 *link)
-{
+int mtp2_start(struct mtp2 *link, int emergency)
+{
+	link->emergency = emergency;
 	return mtp2_setstate(link, MTP_NOTALIGNED);
 }
 

Modified: trunk/mtp2.h
URL: http://svn.digium.com/view/libss7/trunk/mtp2.h?rev=61&r1=60&r2=61&view=diff
==============================================================================
--- trunk/mtp2.h (original)
+++ trunk/mtp2.h Wed Nov  1 16:17:01 2006
@@ -113,7 +113,7 @@
 };
 
 /* Initialize MTP link */
-int mtp2_start(struct mtp2 *link);
+int mtp2_start(struct mtp2 *link, int emergency);
 int mtp2_stop(struct mtp2 *link);
 int mtp2_setstate(struct mtp2 *link, int state);
 struct mtp2 * mtp2_new(int fd, unsigned int switchtype);

Modified: trunk/mtp3.c
URL: http://svn.digium.com/view/libss7/trunk/mtp3.c?rev=61&r1=60&r2=61&view=diff
==============================================================================
--- trunk/mtp3.c (original)
+++ trunk/mtp3.c Wed Nov  1 16:17:01 2006
@@ -194,6 +194,16 @@
 	{ 0xa, 1, "UPU"},
 };
 
+static void mtp3_setstate_mtp2link(struct ss7 *ss7, struct mtp2 *link, int newstate)
+{
+	int i;
+
+	for (i = 0; i < ss7->numlinks; i++) {
+		if (ss7->links[i] == link)
+			ss7->mtp2_linkstate[i] = newstate;
+	}
+}
+
 static char * net_mng_message2str(int h0, int h1)
 {
 	int i;
@@ -267,13 +277,18 @@
 
 	/* Check to see if it's a TRA */
 	if ((h0 == 7) && (h1 == 1)) {
-		ss7_event *e = ss7_next_empty_event(ss7);
-
-		if (!e) {
-			mtp_error(ss7, "Event queue full\n");
-			return -1;
+		ss7_event *e;
+
+		mtp3_setstate_mtp2link(ss7, mtp2, MTP2_LINKSTATE_UP);
+
+		if (ss7->state != SS7_STATE_UP) {
+			e = ss7_next_empty_event(ss7);
+			if (!e) {
+				mtp_error(ss7, "Event queue full\n");
+				return -1;
+			}
+			e->e = SS7_EVENT_UP;
 		}
-		e->e = SS7_EVENT_UP;
 		return 0;
 	} else {
 		ss7_message(ss7, "NET MNG message type %s received\n", net_mng_message2str(h0, h1));
@@ -368,7 +383,7 @@
 
 		return 0;
 	} else if (h1 == 2) {
-		/* Event Link up */
+		net_mng_send_tra(mtp2);
 		return 0;
 	} else
 		ss7_error(ss7, "Unhandled STD_TEST message: h0 = %x h1 = %x", h0, h1);
@@ -519,3 +534,67 @@
 
 	return e;
 }
+
+void mtp3_start(struct ss7 *ss7)
+{
+	int i;
+
+	for (i = 0; i < ss7->numlinks; i++) {
+		if ((ss7->mtp2_linkstate[i] == MTP2_LINKSTATE_DOWN)) {
+			mtp2_start(ss7->links[i], 1);
+			ss7->mtp2_linkstate[i] = MTP2_LINKSTATE_ALIGNING;
+		}
+	}
+	
+	return;
+}
+
+void mtp3_alarm(struct ss7 *ss7, int fd)
+{
+	int i;
+	int winner = -1;
+	int linksup = 0;
+
+	for (i = 0; i < ss7->numlinks; i++) {
+		if (ss7->links[i]->fd == fd) {
+			winner = i;
+			break;
+		}
+	}
+	if (winner > -1)
+		ss7->mtp2_linkstate[winner] = MTP2_LINKSTATE_INALARM;
+
+	for (i = 0; i < ss7->numlinks; i++) {
+		/* Let's count how many links are up while we're going through them */
+		if (ss7->mtp2_linkstate[i] == MTP2_LINKSTATE_UP)
+			linksup++;
+	}
+	if (!linksup) {
+		ss7->state = SS7_STATE_DOWN;
+		ss7_event *e = ss7_next_empty_event(ss7);
+
+		if (!e) {
+			ss7_error(ss7, "Event queue full!");
+			return;
+		}
+		e->e = SS7_EVENT_DOWN;
+		return;
+	}
+}
+
+void mtp3_noalarm(struct ss7 *ss7, int fd)
+{
+	int i;
+	int winner = -1;
+
+	for (i = 0; i < ss7->numlinks; i++) {
+		if (ss7->links[i]->fd == fd) {
+			winner = i;
+			break;
+		}
+	}
+	if (winner > -1) {
+		ss7->mtp2_linkstate[winner] = MTP2_LINKSTATE_ALIGNING;
+		mtp2_start(ss7->links[winner], 1);
+	}
+}

Modified: trunk/mtp3.h
URL: http://svn.digium.com/view/libss7/trunk/mtp3.h?rev=61&r1=60&r2=61&view=diff
==============================================================================
--- trunk/mtp3.h (original)
+++ trunk/mtp3.h Wed Nov  1 16:17:01 2006
@@ -29,6 +29,11 @@
 
 #define SIO_SIZE	1
 
+#define MTP2_LINKSTATE_DOWN 	0
+#define MTP2_LINKSTATE_INALARM	1
+#define MTP2_LINKSTATE_ALIGNING	2
+#define MTP2_LINKSTATE_UP	3
+
 typedef unsigned int point_code;
 
 struct routing_label {
@@ -55,6 +60,12 @@
 /* Transmit */
 int mtp3_transmit(struct ss7 *ss7, unsigned char userpart, unsigned char sls, struct ss7_msg *m);
 
+void mtp3_alarm(struct ss7 *ss7, int fd);
+
+void mtp3_noalarm(struct ss7 *ss7, int fd);
+
+void mtp3_start(struct ss7 *ss7);
+
 unsigned char sls_next(struct ss7 *ss7);
 
 int set_routinglabel(unsigned char *sif, struct routing_label *rl);

Modified: trunk/ss7.c
URL: http://svn.digium.com/view/libss7/trunk/ss7.c?rev=61&r1=60&r2=61&view=diff
==============================================================================
--- trunk/ss7.c (original)
+++ trunk/ss7.c Wed Nov  1 16:17:01 2006
@@ -130,44 +130,20 @@
 	return mtp3_process_event(ss7, e);
 }		
 
-int ss7_start(struct ss7 *ss7)
-{
-	int i = 0;
-
-	for (i = 0; i < ss7->numlinks; i++)
-		mtp2_start(ss7->links[i]);
-
+int  ss7_start(struct ss7 *ss7)
+{
+	mtp3_start(ss7);
 	return 0;
 }
 
 void ss7_link_alarm(struct ss7 *ss7, int fd)
 {
-	int i;
-	int winner = -1;
-
-	for (i = 0; i < ss7->numlinks; i++) {
-		if (ss7->links[i]->fd == fd) {
-			winner = i;
-			break;
-		}
-	}
-	if (winner > -1)
-		mtp2_stop(ss7->links[winner]);
+	mtp3_alarm(ss7, fd);
 }
 
 void ss7_link_noalarm(struct ss7 *ss7, int fd)
 {
-	int i;
-	int winner = -1;
-
-	for (i = 0; i < ss7->numlinks; i++) {
-		if (ss7->links[i]->fd == fd) {
-			winner = i;
-			break;
-		}
-	}
-	if (winner > -1)
-		mtp2_start(ss7->links[winner]);
+	mtp3_noalarm(ss7, fd);
 }
 
 int ss7_add_link(struct ss7 *ss7, int fd)
@@ -267,6 +243,7 @@
 	/* Initialize the event queue */
 	s->ev_h = 0;
 	s->ev_len = 0;
+	s->state = SS7_STATE_DOWN;
 
 	if ((switchtype == SS7_ITU) || (switchtype == SS7_ANSI))
 		s->switchtype = switchtype;

Modified: trunk/ss7_internal.h
URL: http://svn.digium.com/view/libss7/trunk/ss7_internal.h?rev=61&r1=60&r2=61&view=diff
==============================================================================
--- trunk/ss7_internal.h (original)
+++ trunk/ss7_internal.h Wed Nov  1 16:17:01 2006
@@ -36,6 +36,9 @@
 #define MAX_SCHED		64
 #define SS7_MAX_LINKS		4
 
+#define SS7_STATE_DOWN	0
+#define SS7_STATE_UP 1
+
 struct ss7_msg {
 	unsigned char buf[MTP_MAX_SIZE];
 	unsigned int size;
@@ -60,6 +63,7 @@
 
 	unsigned char ni;
 	unsigned char sls;
+	int state;
 
 	unsigned int debug;
 	/* event queue */
@@ -71,6 +75,7 @@
 	struct ss7_sched ss7_sched[MAX_SCHED];
 	struct isup_call *calls;
 
+	unsigned int mtp2_linkstate[SS7_MAX_LINKS];
 	struct mtp2 *links[SS7_MAX_LINKS];
 };
 



More information about the svn-commits mailing list