public void TestSampledInitialAddress() { const string SampleIsupData = "011020010a00020a080310553041b001f00a07031116481017691d038090a300"; var initialAddress = new IsupInitialAddress(); initialAddress.NatureOfConnectionIndicator.EchoControlIncluded = true; initialAddress.ForwardCallIndicator.LoadParameterData(new byte[] { 0x20, 0x01 }); initialAddress.CallingPartyCategory.LoadParameterData(new byte[] { 0x0a }); initialAddress.CalledNumber.Number = "5503140B100F"; initialAddress.CalledNumber.NumberingFlags = NAIFlags.Isdn; initialAddress.CalledNumber.Flags = PhoneFlags.NAINationalNumber; var callingNumber = initialAddress.AddOptionalParameter(new IsupPhoneNumberParameter(IsupParameterType.CallingPartyNumber)); callingNumber.Number = "6184017196"; callingNumber.NumberingFlags |= NAIFlags.ScreeningVerifiedAndPassed; initialAddress.AddOptionalParameter(new OptionalIsupParameter(IsupParameterType.UserServiceInformation, 3, new byte[] { 0x80, 0x90, 0xA3 })); var txt = initialAddress.GetByteArray().ToHex(); for (var i = 0; i < txt.Length; i++) { var exp = SampleIsupData[i].ToString(CultureInfo.InvariantCulture).ToUpperInvariant(); var act = txt[i].ToString(CultureInfo.InvariantCulture).ToUpperInvariant(); Assert.AreEqual(act, exp); } }
public void Fill(InviteMessage invite) { var isup = new IsupInitialAddress(); invite.IsupData = isup; isup.NatureOfConnectionIndicator.EchoControlIncluded = false; isup.NatureOfConnectionIndicator.SatelliteIndicator = NatureOfConnection.SatelliteIndicatorFlags.One; isup.ForwardCallIndicator.LoadParameterData(new byte[] { 0x20, 0x01 }); isup.CallingPartyCategory.LoadParameterData(new byte[] { 0xe0 }); isup.CalledNumber.Number = new string(invite.To.Address.TakeWhile(a => a != '@').ToArray()); isup.CalledNumber.NumberingFlags = NAIFlags.RoutingNotAllowed | NAIFlags.Isdn; isup.CalledNumber.Flags = PhoneFlags.NAINationalNumber; var callingNumber = invite.IsupData.AddOptionalParameter(new IsupPhoneNumberParameter(IsupParameterType.CallingPartyNumber) { Number = invite.From.Address.Split('@').FirstOrDefault() }); callingNumber.NumberingFlags |= NAIFlags.ScreeningVerifiedAndPassed | NAIFlags.NetworProvided; if (this.OriginalCalledNumber != null) { isup.AddOptionalParameter(IsupParameter.OriginalCalledNumber(this.OriginalCalledNumber, callingNumber.Flags)); isup.AddOptionalParameter(IsupParameter.RedirectingNumber(this.OriginalCalledNumber, callingNumber.Flags)); isup.AddRedirInfo(); } }
public static IsupInitialAddress AddRedirInfo( this IsupInitialAddress isup, RedirReason reason = RedirReason.NoReply, byte counter = 1, RedirectInfo.RedirectIndicator indicator = RedirectInfo.RedirectIndicator.CallDiverted) { isup.AddOptionalParameter( new RedirectInfo { RedirectReason = reason, RedirectCounter = counter, RedirectIndicatorFlags = indicator }); return(isup); }
public void TestRedirInfoFilled() { const string SampleIsupData = "01012001e00002070583105194050a0703131419497736080100130204211d038090a33a064405500000000b070314149922700200"; var initialAddress = new IsupInitialAddress(); initialAddress.NatureOfConnectionIndicator.EchoControlIncluded = false; initialAddress.NatureOfConnectionIndicator.SatelliteIndicator = NatureOfConnection.SatelliteIndicatorFlags.One; initialAddress.NatureOfConnectionIndicator.ContinuityCheckIndicator = NatureOfConnection.ContinuityCheckIndicatorFlags.NotRequired; initialAddress.ForwardCallIndicator.LoadParameterData(new byte[] { 0x20, 0x01 }); initialAddress.CallingPartyCategory.CategoryFlags = CallingPartyCategory.Category.Unknown; initialAddress.CalledNumber.Number = "15495"; initialAddress.CalledNumber.NumberingFlags = NAIFlags.Isdn; initialAddress.CalledNumber.Flags = PhoneFlags.NAINationalNumber; var callingNumber = initialAddress.AddOptionalParameter(new IsupPhoneNumberParameter(IsupParameterType.CallingPartyNumber) { Number = "4191947763" }); callingNumber.NumberingFlags = NAIFlags.NetworProvided | NAIFlags.ScreeningVerifiedAndPassed; initialAddress.AddOptionalParameter(new OptionalIsupParameter(IsupParameterType.OptionalForwardCallIndicator, 1)); initialAddress.AddOptionalParameter(new RedirectInfo { RedirectIndicatorFlags = RedirectInfo.RedirectIndicator.RedirectPresentationRestricted, RedirectCounter = 1, RedirectReason = RedirReason.NoReply }); initialAddress.AddOptionalParameter(new OptionalIsupParameter(IsupParameterType.UserServiceInformation, 3, new byte[] { 0x80, 0x90, 0xA3 })); initialAddress.AddOptionalParameter(new OptionalIsupParameter(IsupParameterType.MLPPPrecedence, 6, new byte[] { 0x44, 0x05, 0x50, 0x0, 0x0, 0x0 })); var redirectNumber = initialAddress.AddOptionalParameter(new IsupPhoneNumberParameter(IsupParameterType.RedirectingNumber) { Number = "4199220720" }); redirectNumber.NumberingFlags |= NAIFlags.Isdn | NAIFlags.PresentationRestricted; var txt = initialAddress.GetByteArray().ToHex(); for (var i = 0; i < txt.Length; i++) { var exp = SampleIsupData[i].ToString(CultureInfo.InvariantCulture).ToUpperInvariant(); var act = txt[i].ToString(CultureInfo.InvariantCulture).ToUpperInvariant(); Assert.AreEqual(act, exp); } }
public void DeserializeInviteMessageWithIsupAndSdp(bool includeIsup, bool includeSdp) { MediaGateway.RegisterCodec(MediaGateway.AudioCodec.G711Alaw, () => new AlawMediaCodec(null, null)); const string CallId = "ABC"; const string LocalIp = "127.0.0.1"; Contact to = "[email protected]:5060;user=phone"; var @from = new Contact( "[email protected]:5060", null, new[] { new KeyValuePair <string, string>("user", "phone") }); Contact callerContact = "[email protected]:5060"; var invite = new InviteMessage(CallId, to, @from, @from); var port = MediaGateway.GetNextPort(); if (includeSdp) { invite.SdpData = new Sdp(); invite.SdpData.AddParameter("o", string.Format("- {0} 0 IN IP4 {1}", 10, LocalIp)) .AddParameter("s", "-") .AddParameter("c", "IN IP4 " + LocalIp) .AddParameter("t", "0 0") .AddParameter("m", string.Format("audio {0} RTP/AVP 8 101", port)) .AddParameter("a", "rtpmap:8 PCMA/8000") .AddParameter("a", "rtpmap:101 telephone-event/8000") .AddParameter("a", "fmtp:101 0-15").AddParameter("a", "sendrecv"); } if (includeIsup) { var isup = new IsupInitialAddress(); invite.IsupData = isup; isup.ForwardCallIndicator.LoadParameterData(new byte[] { 0x20, 0x01 }); isup.CallingPartyCategory.CategoryFlags = CallingPartyCategory.Category.Unknown; isup.NatureOfConnectionIndicator.EchoControlIncluded = false; isup.NatureOfConnectionIndicator.ContinuityCheckIndicator = NatureOfConnection.ContinuityCheckIndicatorFlags.NotRequired; isup.NatureOfConnectionIndicator.SatelliteIndicator = NatureOfConnection.SatelliteIndicatorFlags.One; isup.CalledNumber.Number = new string(invite.To.Address.TakeWhile(a => a != '@').ToArray()); isup.CalledNumber.NumberingFlags = NAIFlags.RoutingNotAllowed | NAIFlags.Isdn; isup.CalledNumber.Flags = PhoneFlags.NAINationalNumber; var callingNumber = invite.IsupData.AddOptionalParameter(new IsupPhoneNumberParameter(IsupParameterType.CallingPartyNumber) { Number = invite.From.Address.Split('@').FirstOrDefault() }); callingNumber.NumberingFlags |= NAIFlags.ScreeningVerifiedAndPassed | NAIFlags.NetworProvided; isup.AddOptionalParameter(new IsupPhoneNumberParameter(IsupParameterType.OriginalCalledNumber) { Number = callerContact.Address.Split('@').FirstOrDefault(), Flags = callingNumber.Flags, NumberingFlags = NAIFlags.PresentationRestricted | NAIFlags.Isdn }); isup.AddOptionalParameter(new IsupPhoneNumberParameter(IsupParameterType.RedirectingNumber) { Number = callerContact.Address.Split('@').FirstOrDefault(), Flags = callingNumber.Flags, NumberingFlags = NAIFlags.PresentationRestricted | NAIFlags.Isdn }); isup.AddOptionalParameter(new RedirectInfo { RedirectReason = RedirReason.NoReply, RedirectCounter = 1, RedirectIndicatorFlags = RedirectInfo.RedirectIndicator.CallDiverted }); } if (includeSdp) { invite.Headers["Via"] = string.Format("SIP/2.0/UDP {0}:5060;branch=z9hG4bK7fe{1}", LocalIp, DateTime.Now.Ticks.ToString("X8").ToLowerInvariant()); } var bytes = invite.Serialize(); var deserialized = SipMessage.Parse(bytes) as InviteMessage; Assert.IsNotNull(deserialized, "message isn't an invite"); Assert.That(invite.Contact, Is.EqualTo(deserialized.Contact)); Assert.AreEqual(invite.Contact.ToString(), deserialized.Contact.ToString()); Assert.AreEqual(invite.From, deserialized.From); Assert.AreEqual(invite.To, deserialized.To); if (includeSdp) { Assert.AreEqual(invite.SdpData.ContentText, deserialized.SdpData.ContentText); } if (includeIsup) { Assert.AreEqual(invite.IsupData.GetByteArray().ToHex().ToUpper(), deserialized.IsupData.GetByteArray().ToHex().ToUpper()); } Assert.AreEqual(invite.Method, deserialized.Method); }