ussd: Send USSD on call setup on MSC errors

Send an USSD message to the mobile station requesting a connection
for a call or a SMS when the link to the MSC is down or in the
grace period.

The messages can be set (and this feature activated) by setting
bsc/missing-msc-text resp. msc/bsc-grace-text via the vty.

The generation of both messages has been tested manually.

Ticket: OW#957
diff --git a/openbsc/tests/vty_test_runner.py b/openbsc/tests/vty_test_runner.py
index ab9670c..460b70e 100644
--- a/openbsc/tests/vty_test_runner.py
+++ b/openbsc/tests/vty_test_runner.py
@@ -207,7 +207,7 @@
         self.vty.command("msc 0")
         self.assertEquals(self.vty.node(), 'config-msc')
 
-    def testUssdNotifications(self):
+    def testUssdNotificationsMsc(self):
         self.vty.enable()
         self.vty.command("configure terminal")
         self.vty.command("msc")
@@ -215,10 +215,12 @@
         # Test invalid input
         self.vty.verify("bsc-msc-lost-text", ['% Command incomplete.'])
         self.vty.verify("bsc-welcome-text", ['% Command incomplete.'])
+        self.vty.verify("bsc-grace-text", ['% Command incomplete.'])
 
         # Enable USSD notifications
         self.vty.verify("bsc-msc-lost-text MSC disconnected", [''])
         self.vty.verify("bsc-welcome-text Hello MS", [''])
+        self.vty.verify("bsc-grace-text In grace period", [''])
 
         # Verify settings
         res = self.vty.command("write terminal")
@@ -226,17 +228,46 @@
         self.assertEquals(res.find('no bsc-msc-lost-text'), -1)
         self.assert_(res.find('bsc-welcome-text Hello MS') > 0)
         self.assertEquals(res.find('no bsc-welcome-text'), -1)
+        self.assert_(res.find('bsc-grace-text In grace period') > 0)
+        self.assertEquals(res.find('no bsc-grace-text'), -1)
 
         # Now disable it..
         self.vty.verify("no bsc-msc-lost-text", [''])
         self.vty.verify("no bsc-welcome-text", [''])
+        self.vty.verify("no bsc-grace-text", [''])
 
         # Verify settings
         res = self.vty.command("write terminal")
         self.assertEquals(res.find('bsc-msc-lost-text MSC disconnected'), -1)
         self.assert_(res.find('no bsc-msc-lost-text') > 0)
-        self.assert_(res.find('no bsc-welcome-text') > 0)
         self.assertEquals(res.find('bsc-welcome-text Hello MS'), -1)
+        self.assert_(res.find('no bsc-welcome-text') > 0)
+        self.assertEquals(res.find('bsc-grace-text In grace period'), -1)
+        self.assert_(res.find('no bsc-grace-text') > 0)
+
+    def testUssdNotificationsBsc(self):
+        self.vty.enable()
+        self.vty.command("configure terminal")
+        self.vty.command("bsc")
+
+        # Test invalid input
+        self.vty.verify("missing-msc-text", ['% Command incomplete.'])
+
+        # Enable USSD notifications
+        self.vty.verify("missing-msc-text No MSC found", [''])
+
+        # Verify settings
+        res = self.vty.command("write terminal")
+        self.assert_(res.find('missing-msc-text No MSC found') > 0)
+        self.assertEquals(res.find('no missing-msc-text'), -1)
+
+        # Now disable it..
+        self.vty.verify("no missing-msc-text", [''])
+
+        # Verify settings
+        res = self.vty.command("write terminal")
+        self.assertEquals(res.find('missing-msc-text No MSC found'), -1)
+        self.assert_(res.find('no missing-msc-text') > 0)
 
 class TestVTYNAT(TestVTYGenericBSC):