Erlang SGSN

Embed Size (px)

Citation preview

  • 8/20/2019 Erlang SGSN

    1/32

    Functional Programming inFunctional Programming inindustryindustry

    ERLANG

    Courtesy of Urban Boquist and Christer Nilsson (Ericsson Gothenburg)

    Leslaw Lopacki

    leslawlopacki!net

  • 8/20/2019 Erlang SGSN

    2/32

    OutlineOutline

    " Mobile Telecommunications NetworksMobile Telecommunications Networks

    " Packet Core Network – GPRS, MTS ! SGSNPacket Core Network – GPRS, MTS ! SGSN

    " se o" #rlang in SGSNse o" #rlang in SGSN

    "

    SGSN $esign Princi%les "or #rlang&SGSN $esign Princi%les "or #rlang&

    concurrencyconcurrency

    distributiondistribution

    "ault tolerance"ault tolerance

    o'erload %rotectiono'erload %rotection

    runtime code re%lacementruntime code re%lacement" #rlang basics and e(am%les#rlang basics and e(am%les

  • 8/20/2019 Erlang SGSN

    3/32

    Mobile TelecommunicationsMobile Telecommunications

    Networks ) GSMNetworks ) GSM

    CS # circuit switched

    ● $oice● %&%

    PS # packet switched● e$erything that is '*● wap + www● e,ail●

     &&%

    %er$ices in teleco,,unications networks-

    G.% / General acket .adio %er$ice

  • 8/20/2019 Erlang SGSN

    4/32

    Packet Core NetworkPacket Core Network.adio Network acket Core Network

    " GSN *GPRS Su%%ort Network+ nodes&GSN *GPRS Su%%ort Network+ nodes& SGSNSGSN # # Ser'ing GSNSer'ing GSN GGSNGGSN # # Gateway GSNGateway GSN

    " asic t-roug-%ut&asic t-roug-%ut& % to ../ kb%s wit- GPRS% to ../ kb%s wit- GPRS % to 012 kb%s wit- #$G#% to 012 kb%s wit- #$G# # # #n-anced $ata Rates "or GSM #'olution#n-anced $ata Rates "or GSM #'olution

  • 8/20/2019 Erlang SGSN

    5/32

    PCN in 34G5 and 3Turbo)4G5 –PCN in 34G5 and 3Turbo)4G5 –

    6C$M7 and 8S$P76C$M7 and 8S$P7" $i9erent Radio Network$i9erent Radio Network" Packet Core Network *almost+ t-e same as t-e one in GPRSPacket Core Network *almost+ t-e same as t-e one in GPRS" #ricsson SGSN is 3dual access5 – GPRS and 6C$M7 in one#ricsson SGSN is 3dual access5 – GPRS and 6C$M7 in one" Muc- -ig-er *end user+ s%eeds&Muc- -ig-er *end user+ s%eeds&

    % to 4:1 kb%s "or 4G *6C$M7+% to 4:1 kb%s "or 4G *6C$M7+% to .1;1 Mb%s "or 8S$P7 *later u% to 10 Mbit – #'ol'ed% to .1;1 Mb%s "or 8S$P7 *later u% to 10 Mbit – #'ol'ed8SP7+8SP7+

    "

    " Streaming 'ideo is PSStreaming 'ideo is PS*T< ?? MMS – Multimedia roadcast Multicast Ser'ice+*T< ?? MMS – Multimedia roadcast Multicast Ser'ice+

    " Future& 'oice = 'ideo in PSFuture& 'oice = 'ideo in PS" 33

  • 8/20/2019 Erlang SGSN

    6/32

    #ricsson SGSN Node#ricsson SGSN Node

    Capacity0 1 23 k subscribers4 5333

    0 1 633 k subscribers4 53350 1 233 k subscribers4 53370 1 6 & subscribers4 53320 ~  5 & subscribers4 5338

  • 8/20/2019 Erlang SGSN

    7/32

    SGSN – asic Ser'icesSGSN – asic Ser'ices

    " aut-enticationaut-entication

    " admission controladmission control" Auality o" ser'iceAuality o" ser'ice

    " mobilitymobility

    " roamingroaming

    "

    ;;;;;;

    Control %ignalling ayload transport

    " user traBcuser traBc

    " c-argingc-arging

  • 8/20/2019 Erlang SGSN

    8/32

    SGSN 7rc-itectureSGSN 7rc-itecture

    C CCC

    !!!

    !!!

    Control lane

    ayload lane

    %witch

    &% nternet

    soft real time

    hard real time

  • 8/20/2019 Erlang SGSN

    9/32

    SGSN 8ardwareSGSN 8ardware" 02)42 Control Processors *boards+&02)42 Control Processors *boards+&

    ltraSP7RC or PowerPC CPsltraSP7RC or PowerPC CPs

    0 G memory0 G memory

    Solaris=Dinu( E #rlang = C = CEESolaris=Dinu( E #rlang = C = CEE

    " 02)42 Payload Processors *boards+&02)42 Payload Processors *boards+& PowerPC CPsPowerPC CPs

    S%ecial -ardware *FPG7s+ "or encry%tionS%ecial -ardware *FPG7s+ "or encry%tion

    P-ysical de'ices& "rame relay, atm, ;;;P-ysical de'ices& "rame relay, atm, ;;;

  • 8/20/2019 Erlang SGSN

    10/32

    SGSN Control SignallingSGSN Control Signalling

    " attac- *%-one is turned on+attac- *%-one is turned on+

    " israu *routing area u%date, mobility in radio network+israu *routing area u%date, mobility in radio network+

    " acti'ation *initiate %ayload traBc+acti'ation *initiate %ayload traBc+

    "etc; -undreds o" signalsetc; -undreds o" signals

    9eleco, standards are :UGE (see www!;gpp!org)<

    =e need a high le$el language # concentrate on

    G.%4 not on progra,,ing details<

  • 8/20/2019 Erlang SGSN

    11/32

    #rlang=OTP#rlang=OTP

    " @n'ented at #ricsson Com%uter Science Dab in t-e@n'ented at #ricsson Com%uter Science Dab in t-e

    .H:2s;.H:2s;

    " @ntended "or large scale reliable telecom systems;@ntended "or large scale reliable telecom systems;

    "

    #rlang isrlang is& "unctional language"unctional language

    wit- built)in su%%ort "or concurrencywit- built)in su%%ort "or concurrency

    " OTP *O%en Telecom Plat"orm+OTP *O%en Telecom Plat"orm+

    ?? #rlang E lots o" libraries;?? #rlang E lots o" libraries;

  • 8/20/2019 Erlang SGSN

    12/32

    6-y #rlangI6-y #rlangI

    " Good t-ings in #rlang&Good t-ings in #rlang&

    built)in concurrency *%rocesses and message %assing+built)in concurrency *%rocesses and message %assing+

    built)in distributionbuilt)in distribution

    built)in "ault)tolerancebuilt)in "ault)tolerance

    su%%ort "or runtime code re%lacementsu%%ort "or runtime code re%lacement a dynamic languagea dynamic language

    a dynamically ty%ed languagea dynamically ty%ed language

    "  T-is is e(actly w-at is needed to build a robust Control Plane in a T-is is e(actly w-at is needed to build a robust Control Plane in a

    telecom system>telecom system>

    @n SGSN&@n SGSN&

    " Control Plane So"tware is not time critical *#rlang+Control Plane So"tware is not time critical *#rlang+

    " ser Plane *%ayload+ is time critical *C+ser Plane *%ayload+ is time critical *C+

  • 8/20/2019 Erlang SGSN

    13/32

    #rlang – Concurrency#rlang – Concurrency

    " 33Normal5 sync-roniJation %rimiti'es ) sema%-ores or monitorsNormal5 sync-roniJation %rimiti'es ) sema%-ores or monitors

    does not look t-e same in #rlangdoes not look t-e same in #rlang

    instead e'eryt-ing is done wit- %rocesses and messageinstead e'eryt-ing is done wit- %rocesses and message%assing;%assing;

    " Mutual e(clusion&Mutual e(clusion& use a single %rocess to -andle resourceuse a single %rocess to -andle resource

    clients call %rocess to get access;clients call %rocess to get access;

    " Critical sections&Critical sections&

    allow only one %rocess to e(ecute sectionallow only one %rocess to e(ecute section

  • 8/20/2019 Erlang SGSN

    14/32

    #rlang ) $istribution#rlang ) $istribution" General rule in SGSN&General rule in SGSN&

    a'oid remote communication or sync-roniJation i" %ossiblea'oid remote communication or sync-roniJation i" %ossible

    " $esign algorit-ms t-at work inde%endently on eac- node&$esign algorit-ms t-at work inde%endently on eac- node&

    "ault tolerance"ault tolerance

    load balancingload balancing" 7'oid relying on global resources7'oid relying on global resources

    " $ata -andling&$ata -andling&

    kee% as muc- locally as %ossible *ty%ically traBc datakee% as muc- locally as %ossible *ty%ically traBc data

    associated wit- mobile %-ones+associated wit- mobile %-ones+ some data must be distributed = s-ared *e;g; using mnesia+some data must be distributed = s-ared *e;g; using mnesia+

    many di9erent 'ariants o" %ersistency, redundancy,many di9erent 'ariants o" %ersistency, redundancy,

    re%licationre%lication

  • 8/20/2019 Erlang SGSN

    15/32

    Fault ToleranceFault Tolerance" SGSN must ne'er be out)o")ser'ice> *HH;HHHK+SGSN must ne'er be out)o")ser'ice> *HH;HHHK+

    " 8ardware "ault tolerance8ardware "ault tolerance

    Faulty boards are automatically taken out o" ser'iceFaulty boards are automatically taken out o" ser'ice

    Mobile %-ones automatically redistributedMobile %-ones automatically redistributed

    " So"tware "ault toleranceSo"tware "ault tolerance S6 error triggered by one %-one s-ould not a9ect ot-ers>S6 error triggered by one %-one s-ould not a9ect ot-ers>

    Serious error in 3system S65 s-ould a9ect at most t-eSerious error in 3system S65 s-ould a9ect at most t-e

    %-ones -andled by t-at board *not t-e w-ole node+%-ones -andled by t-at board *not t-e w-ole node+

    :ow can such require,ents be reali>ed?

    E@a,ple- the %= handling one phone goes cra>y and o$erwrites all the

    ,e,ory with garbage!

  • 8/20/2019 Erlang SGSN

    16/32

    SGSN 7rc-itecture – ControlSGSN 7rc-itecture – Control

    PlanePlane

    " On eac- CP .22 %rocesses %ro'iding 3system ser'ices5On eac- CP .22 %rocesses %ro'iding 3system ser'ices5 33static workers5static workers5

    " On eac- CP /2;222 %rocesses eac- -andling one %-oneOn eac- CP /2;222 %rocesses eac- -andling one %-one 33dynamic workers5dynamic workers5

    C C C

  • 8/20/2019 Erlang SGSN

    17/32

    $ynamic workers$ynamic workers

    " System %rinci%le&System %rinci%le&

    one #rlang %rocess -andles all signalling wit- a singleone #rlang %rocess -andles all signalling wit- a singlemobile %-onemobile %-one

    " 6-en a signal recei'ed in %ayload %lane&6-en a signal recei'ed in %ayload %lane&

    %ayload %lane translates a 3signal5 "rom t-e mobile %-one%ayload %lane translates a 3signal5 "rom t-e mobile %-one

    into an #rlang messageinto an #rlang message

    t-en sends it to t-e correct dynamic worker, and 'ice 'ersat-en sends it to t-e correct dynamic worker, and 'ice 'ersa

    "

    7 worker -as a state mac-ine&7 worker -as a state mac-ine& recei'e a signal – do some com%utation – send a re%lyrecei'e a signal – do some com%utation – send a re%ly

    signalsignal

    a little bit like an #ntity ean in L0##a little bit like an #ntity ean in L0##

  • 8/20/2019 Erlang SGSN

    18/32

    $ynamic workers cont;$ynamic workers cont;" 7 %rocess cras- s-ould ne'er a9ect ot-er mobiles&7 %rocess cras- s-ould ne'er a9ect ot-er mobiles&

    #rlang guarantees memory %rotection#rlang guarantees memory %rotection

    " S6 errors in SGSN&S6 errors in SGSN&

    lead to a s-ort ser'ice outage "or t-e %-onelead to a s-ort ser'ice outage "or t-e %-one

    dynamic worker will be restarted a"ter t-e cras-dynamic worker will be restarted a"ter t-e cras-

    " Same "or S6 errors in MS&Same "or S6 errors in MS&

    e;g; "ailure to "ollow standards will cras- dynamic workere;g; "ailure to "ollow standards will cras- dynamic worker*o9ensi'e %rogramming+*o9ensi'e %rogramming+

  • 8/20/2019 Erlang SGSN

    19/32

    Su%er'ision and #scalationSu%er'ision and #scalation

    " Cras- o" worker is noticed by su%er'isorCras- o" worker is noticed by su%er'isor

    " Su%er'isor triggers 3reco'ery action5Su%er'isor triggers 3reco'ery action5

    " #it-er t-e cras-ed worker is restarted#it-er t-e cras-ed worker is restartedor or 

    " 7ll workers are killed and restarted7ll workers are killed and restarted

    %uper$isor 

    =orker6 =orker5 =orker;

  • 8/20/2019 Erlang SGSN

    20/32

    Runtime code re%lacementRuntime code re%lacement" Fact& S6 is ne'er bug "ree>Fact& S6 is ne'er bug "ree>

    " Must be able to install error corrections into alreadyMust be able to install error corrections into already

    deli'ered systems wit-out disturbing o%erationdeli'ered systems wit-out disturbing o%eration" #rlang can load a new 'ersion o" a module in a#rlang can load a new 'ersion o" a module in a

    running systemrunning system

    " e care"ul>e care"ul>

    Code loading reAuires co)o%eration "rom t-eCode loading reAuires co)o%eration "rom t-erunning S6 and great care "rom t-e S6 designerrunning S6 and great care "rom t-e S6 designer

  • 8/20/2019 Erlang SGSN

    21/32

    O'erload ProtectionO'erload Protection" @" CP load or memory usage goes to -ig- SGSN will@" CP load or memory usage goes to -ig- SGSN will

    not acce%t new connections "rom mobile %-onesnot acce%t new connections "rom mobile %-ones

    " T-e SGSN must ne'er sto% to 3res%ond5 because o" T-e SGSN must ne'er sto% to 3res%ond5 because o"o'erload, better to ski% ser'ice "or some %-oneso'erload, better to ski% ser'ice "or some %-ones

    " RealiJed in message %assing ) i" ODP -its messagesRealiJed in message %assing ) i" ODP -its messages

    are discarded&are discarded&

    silently dro%%edsilently dro%%ed or a denial re%ly generatedor a denial re%ly generated

  • 8/20/2019 Erlang SGSN

    22/32

    #rlang basic synta(#rlang basic synta(

    " Erlang shellErlang shell &&

    erlerl

    " &odules and Aunctions-&odules and Aunctions-

    -module(my_mod).-module(my_mod).-export(double/1).-export(double/1).

    double(X) -> 2 * X.double(X) -> 2 * X.

    " Calling double+6-Calling double+6-

    my_mod:double(4).my_mod:double(4).

    "  to,s- to,s-

    cat, dog, home, a2 ..cat, dog, home, a2 ..

    " 9uples -9uples -

    1,2,cat,home!1,2,cat,home!

    " Lists -Lists -

    "1,2,cat,home!,1,2,#$"1,2,cat,home!,1,2,#$

    " ariables -ariables -

    % & 2,#,hor'e,'table!.% & 2,#,hor'e,'table!. & "1,2,cat,home!,1,2,#$. & "1,2,cat,home!,1,2,#$.

    ar & "%$.ar & "%$.

    " =riting to output-=riting to output-

    +o:ormat(ello orld0).+o:ormat(ello orld0).

  • 8/20/2019 Erlang SGSN

    23/32

    #rlang synta( ) case and#rlang synta( ) case and"unctional clause"unctional clause

    " Case clause ) case and %attern matc-ing&Case clause ) case and %attern matc-ing&

    oc &oc &

    ca'e ar oca'e ar o  _,_,cat,X! -> +o:ormat(ello 3at0),X_,_,cat,X! -> +o:ormat(ello 3at0),X  _,_,hor'e,X! -> +o:ormat(ello or'e0),X_,_,hor'e,X! -> +o:ormat(ello or'e0),X_ -> +o:ormat(5o e6tra6ce0),6o6e_ -> +o:ormat(5o e6tra6ce0),6o6e

      e6d.e6d.

    " Function clause&Function clause&

    hello(_,_,cat,X!) -> +o:ormat(ello 3at0),Xhello(_,_,cat,X!) -> +o:ormat(ello 3at0),X

    hello(_,_,hor'e,X!) -> +o:ormat(ello or'e0),X.hello(_,_,hor'e,X!) -> +o:ormat(ello or'e0),X.

    hello(_) -> +o:ormat(5o e6tra6ce0),6o6e.hello(_) -> +o:ormat(5o e6tra6ce0),6o6e.

  • 8/20/2019 Erlang SGSN

    24/32

    #rlang synta( ) Recursion#rlang synta( ) Recursion

    " %i,ple-%i,ple-

    -module(act).-module(act).-export("act1/1$).-export("act1/1$).

    act1(7) ->act1(7) ->11

    act1(5) ->act1(5) ->5*act1(5-1).5*act1(5-1). 

    " Dpti,al / tail recursi$e-Dpti,al / tail recursi$e-

    -module(act).-module(act).

    -export("act2/1$).-export("act2/1$).

    act2(5) ->act2(5) ->act2(5,1).act2(5,1).

    act2(7,%) ->act2(7,%) ->%%

    act2(5,%) ->act2(5,%) ->

    act2(5-1,5*%).act2(5-1,5*%). 

  • 8/20/2019 Erlang SGSN

    25/32

    #rlang ad'anced synta(#rlang ad'anced synta(

    " $ynamic code&$ynamic code&

    8u6 & u6(ar)8u6 & u6(ar)

    ca'e ar oca'e ar o

      _,_,cat,X! -> +o:ormat(ello 3at0),X_,_,cat,X! -> +o:ormat(ello 3at0),X

      _,_,hor'e,X! -> +o:ormat(ello or'e0),X_,_,hor'e,X! -> +o:ormat(ello or'e0),X_ -> +o:ormat(5ot elcome here0),6o6e  _ -> +o:ormat(5ot elcome here0),6o6e

      e6d.e6d.

       

    Calling Fun&Calling Fun&

    8u6(1,2,cat,home!).8u6(1,2,cat,home!).

    Passing Fun to anot-er "unction&Passing Fun to anot-er "unction&

    call_u6(8u6,"$) -> o9call_u6(8u6,"$) -> o9

    call_u6(8u6,"X$) -> 8u6(X), call_u6(8u6,).call_u6(8u6,"X$) -> 8u6(X), call_u6(8u6,).

    +'t & "1,2,cat,home!,2,#,hor'e,'table!$.+'t & "1,2,cat,home!,2,#,hor'e,'table!$.call_u6(8u6,+'t).call_u6(8u6,+'t).

  • 8/20/2019 Erlang SGSN

    26/32

    #rlang message %assing#rlang message %assing

    sender&sender&

    ;+d < ='g,;+d < ='g,

    recei'er&recei'er&

    rece+erece+e='g ->='g ->?act+o6>?act+o6>

    e6d,e6d,

  • 8/20/2019 Erlang SGSN

    27/32

    #(am%le cont; ) genser'er#(am%le cont; ) genser'er

    sender&sender&

    @et & ge6_'erer:call(;+d, ='g),@et & ge6_'erer:call(;+d, ='g),

    recei'er&recei'er&

    ha6dle_call(='g) ->ha6dle_call(='g) ->ca'e ='g oca'e ='g o

    add, 5! ->add, 5! ->

    reply, 5 A 1!reply, 5 A 1!

    ......

    e6d.e6d.

  • 8/20/2019 Erlang SGSN

    28/32

  • 8/20/2019 Erlang SGSN

    29/32

    ConclusionsConclusions

    Pros&Pros&

    " #rlang works well "or GPRS traBc control -andling#rlang works well "or GPRS traBc control -andling

    " 8ig- le'el language – concentrate on im%ortant %arts8ig- le'el language – concentrate on im%ortant %arts

    " 8as t-e rig-t ca%abilities&8as t-e rig-t ca%abilities&

    "ault tolerance"ault tolerance

    distributiondistribution ;;;;;;

    Cons&Cons&

    " 8ard to nd good #rlang %rogrammers8ard to nd good #rlang %rogrammers

    " #rlang=OTP not yet a main stream language#rlang=OTP not yet a main stream language

    @nsuBcient %rogramming en'ironments *debugging, modelling, etc+@nsuBcient %rogramming en'ironments *debugging, modelling, etc+ Single im%lementation maintained by too "ew %eo%le ) bugsSingle im%lementation maintained by too "ew %eo%le ) bugs

    " 8ig- le'el language – easy to create a real mess in ust a "ew lines o"8ig- le'el language – easy to create a real mess in ust a "ew lines o"

    code;;;code;;;

  • 8/20/2019 Erlang SGSN

    30/32

    Dinks and Re"erencesDinks and Re"erences

    " #rlang siterlang site&

    -tt%&==www;erlang;org-tt%&==www;erlang;org

    " #rlang ser Con"erence *No' 022:+#rlang ser Con"erence *No' 022:+" #rlang Communityrlang Community&

    -tt%&==tra%e(it;org-tt%&==tra%e(it;org

    " #rlang grou% on Dinked@n#rlang grou% on Dinked@n

    http://www.erlang.org/http://www.erlang.org/http://trapexit.org/http://trapexit.org/http://trapexit.org/http://www.erlang.org/

  • 8/20/2019 Erlang SGSN

    31/32

    ooksooks

    " ! r,strong! r,strong

    “Programming Erlang” “Programming Erlang” 

    " ! r,strong4 .! irding4 C! =ikstrF,4! r,strong4 .! irding4 C! =ikstrF,4

    &! =illia,s&! =illia,s

    “Concurrent Programming in Erlang” “Concurrent Programming in Erlang” 

  • 8/20/2019 Erlang SGSN

    32/32

    uestionsIuestionsI