bsc/ussd: Optionally send USSD message on MSC disconnection

Send an USSD message on each MS connection if the connection to
the MSC has been lost.
Add a vty config command 'bsc-msc-loss-txt' in 'config-msc' to set
the notification string and to enable the feature.

Ticket: OW#957
diff --git a/openbsc/tests/vty_test_runner.py b/openbsc/tests/vty_test_runner.py
index a7a7b3f..fd200c8 100644
--- a/openbsc/tests/vty_test_runner.py
+++ b/openbsc/tests/vty_test_runner.py
@@ -88,6 +88,39 @@
         self.assertEquals(res.find('periodic location update 60'), -1)
         self.assert_(res.find('no periodic location update') > 0)
 
+class TestVTYBSC(TestVTYBase):
+
+    def vty_command(self):
+        return ["./src/osmo-bsc/osmo-bsc", "-c",
+                "doc/examples/osmo-bsc/osmo-bsc.cfg"]
+
+    def vty_app(self):
+        return (4242, "./src/osmo-bsc/osmo-bsc", "OsmoBSC", "bsc")
+
+    def testUssdNotifications(self):
+        self.vty.enable()
+        self.vty.command("configure terminal")
+        self.vty.command("msc")
+
+        # Test invalid input
+        self.vty.verify("bsc-msc-lost-text", ['% Command incomplete.'])
+
+        # Enable USSD notifications
+        self.vty.verify("bsc-msc-lost-text MSC disconnected", [''])
+
+        # Verify settings
+        res = self.vty.command("write terminal")
+        self.assert_(res.find('bsc-msc-lost-text MSC disconnected') > 0)
+        self.assertEquals(res.find('no bsc-msc-lost-text'), -1)
+
+        # Now disable it..
+        self.vty.verify("no bsc-msc-lost-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)
+
 class TestVTYNAT(TestVTYBase):
 
     def vty_command(self):
@@ -189,6 +222,13 @@
     test = unittest.TestLoader().loadTestsFromTestCase(TestVTYNAT)
     suite.addTest(test)
 
+def add_bsc_test(suite, workdir):
+    if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc/osmo-bsc")):
+        print("Skipping the BSC test")
+        return
+    test = unittest.TestLoader().loadTestsFromTestCase(TestVTYBSC)
+    suite.addTest(test)
+
 if __name__ == '__main__':
     import argparse
     import sys
@@ -219,6 +259,7 @@
     print "Running tests for specific VTY commands"
     suite = unittest.TestSuite()
     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYNITB))
+    add_bsc_test(suite, workdir)
     add_nat_test(suite, workdir)
     res = unittest.TextTestRunner(verbosity=verbose_level).run(suite)
     sys.exit(len(res.errors) + len(res.failures))