Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

10장 port와 interface

9장에서는 배터리와 비행 제어기를 part끼리 바로 이었습니다. 이렇게 적으면 둘이 이어져 있다는 것은 알 수 있지만, 배터리의 어느 지점으로 무엇이 나가는지는 알 수 없습니다. 부품을 만드는 쪽과 조립하는 쪽이 따로 일하려면 부품의 안쪽을 보지 않고도 연결할 수 있어야 합니다. port는 part가 바깥과 만나는 지점을 그 part의 경계에 선언한 것이고, interface는 port와 port를 잇는 connection입니다. 둘을 쓰면 part의 내부 구조를 감춘 채로, 무엇이 어느 방향으로 드나드는지를 정할 수 있습니다.

port definition과 port usage

port definition은 연결 지점의 종류를 정의합니다. 본문에는 그 지점으로 드나드는 것과 그 지점의 특성을 선언합니다.

port def PowerPort {
    out item power : ElectricPower;
    attribute voltage : ElectricPotentialValue;
}

part def Battery {
    attribute capacity : EnergyValue;
    port powerOut : PowerPort;
}

Battery는 PowerPort를 type으로 갖는 port usage powerOut을 하나 가집니다. port의 feature는 direction에 따라 뜻이 갈립니다.

port의 feature뜻PowerPort의 예
out이 port로 나가는 것power
in이 port로 들어오는 것
inout양쪽으로 오가는 것
direction 없음연결 지점의 특성voltage

direction의 기준은 port를 가진 part입니다. Battery의 powerOut에서 power가 out이므로, 전력은 배터리에서 바깥으로 나갑니다.

port에는 다음 규칙이 적용됩니다.

  • port usage의 type은 port definition이어야 합니다.
  • definition이나 usage 안에 선언한 port usage의 multiplicity는 적지 않으면 [1..1]입니다. 같은 종류의 접점이 여럿이면 port motorOut : PowerPort[4];처럼 적습니다.
  • port definition과 port usage의 본문에 선언하는 usage는 referential이어야 합니다. port는 드나드는 것을 가리킬 뿐 소유하지 않습니다. direction이 있는 usage와 attribute usage는 언제나 referential이므로 ref를 적지 않아도 됩니다.

셋째 규칙 때문에 다음 선언은 오류입니다. part는 composite usage입니다.

port def ServicePort {
    part technician : Operator;
}

conjugation

전력을 내보내는 port가 있으면 받는 port도 있어야 합니다. 받는 쪽을 위해 in item power를 가진 port definition을 따로 만들면, 한쪽을 고칠 때 다른 쪽을 잊어 둘이 어긋날 수 있습니다. 그래서 SysML은 port definition마다 direction만 뒤집은 짝을 자동으로 만들어 둡니다. 이 짝이 conjugated port definition이며, 원래 이름 앞에 ~를 붙여 가리킵니다.

part def FlightController {
    port powerIn : ~PowerPort;
}

~PowerPort의 feature는 PowerPort의 feature와 같고 direction만 다릅니다.

PowerPort~PowerPort
out item powerin item power
attribute voltageattribute voltage

in은 out으로, out은 in으로 바뀌고, inout과 direction이 없는 feature는 그대로입니다. 그러므로 FlightController의 powerIn으로는 전력이 들어옵니다.

양쪽으로 오가는 것이 있는 port도 같은 방식으로 짝을 이룹니다. 지상 통제소는 명령을 내보내고 상태 보고를 받으며, 드론은 그 반대입니다.

port def CommandPort {
    out item command : FlightCommand;
    in item status : StatusReport;
}

part def GroundStation {
    port commandPort : CommandPort;
}

part def Radio {
    port uplink : ~CommandPort;
    port commandOut : CommandPort;
}

Radio는 uplink로 명령을 받고 상태 보고를 내보냅니다. 받은 명령은 commandOut으로 비행 제어기에 넘깁니다.

두 port는 한쪽의 feature마다 다른 쪽에 짝이 되는 feature가 있을 때 서로 맞습니다. 짝이 되려면 type이 맞아야 하고, direction은 둘 다 없거나 in과 out처럼 서로 반대여야 합니다. P와 ~P는 만들어진 방식 때문에 언제나 맞습니다. 어느 쪽을 원래 definition으로 삼을지는 모델 작성자가 정하며, 한 모델 안에서는 기준을 하나로 지켜야 읽기 쉽습니다. 이 책의 예제는 전력을 공급하는 쪽과 명령을 보내는 쪽을 원래 definition으로 삼았습니다.

interface

interface는 end가 모두 port인 connection입니다. 선언하는 방법은 9장의 connection과 같고 키워드만 interface로 바뀝니다.

interface def PowerInterface {
    end supplier : PowerPort;
    end consumer : ~PowerPort;
}

part def Drone {
    part battery : Battery;
    part flightController : FlightController;

    interface powerLine : PowerInterface
        connect battery.powerOut to flightController.powerIn;
}
flowchart LR
    subgraph battery["battery : Battery"]
        po(["`**powerOut**
        PowerPort`"])
    end
    subgraph fc["flightController : FlightController"]
        pi(["`**powerIn**
        ~PowerPort`"])
    end
    po -- "powerLine : PowerInterface" --- pi

interface definition의 end는 port usage이므로 end 선언에서 port 키워드를 생략할 수 있습니다. PowerInterface는 공급하는 쪽의 PowerPort와 받는 쪽의 ~PowerPort를 잇는다고 정해 두었으므로, 전원을 잇는 곳마다 이 definition을 다시 씁니다. 충전 스테이션이 드론에 전력을 공급하는 연결도 같은 PowerInterface로 선언할 수 있습니다.

interface definition 없이 port 둘을 바로 이을 수도 있습니다. 이때에는 connect를 생략합니다.

interface battery.powerOut to flightController.powerIn;

9장에서 본 end 이름 표기, end 앞의 multiplicity, end를 본문에 선언하는 형식은 interface usage에도 그대로 쓸 수 있습니다.

port를 connect로 이어도 문법에는 맞지만 그것은 interface가 아닙니다. 둘의 차이는 다음과 같습니다.

connect로 선언한 connectioninterface
end에 올 수 있는 것제한이 없습니다.port usage만 올 수 있습니다.
port를 거쳐 보낸 것이 connection을 따라 전달되지 않습니다.반대쪽 end의 port로 전달됩니다.

action이 어떤 port를 거쳐 item을 보내면, 그 item은 그 port에 이어진 interface의 반대쪽 port에 닿습니다. 이 전달은 interface에서만 일어나므로, port 사이로 무언가가 오가는 연결은 interface로 선언해야 합니다. 보내고 받는 action은 19장에서 다룹니다.

interface 안에 적는 것

interface definition도 connection definition이므로 본문에 end 말고 다른 것을 선언할 수 있습니다. 양쪽 port 사이에서 실제로 흐르는 것과 양쪽 port의 feature 사이에 성립해야 하는 조건을 여기에 적습니다.

interface def PowerInterface {
    end supplier : PowerPort;
    end consumer : ~PowerPort;

    flow of ElectricPower from supplier.power to consumer.power;
    assert constraint { supplier.voltage == consumer.voltage }
}

flow는 supplier의 power에서 consumer의 power로 전력이 옮겨 간다는 선언이고, assert constraint는 양쪽 접점의 전압이 같아야 한다는 조건입니다. flow는 19장에서, constraint는 13장에서 설명합니다.

경계의 port와 안쪽의 port

드론 전체를 part 하나로 보면 드론에도 바깥과 만나는 port가 있습니다. 지상 통제소의 명령은 드론의 port로 들어와 안쪽의 radio에 닿습니다. 드론의 port와 radio의 port가 같은 접점이라는 것은 9장의 binding으로 적습니다.

part def Drone {
    part radio : Radio;
    part flightController : FlightController;

    port commandPort : ~CommandPort;
    bind commandPort = radio.uplink;

    interface commandLine : CommandLink
        connect radio.commandOut to flightController.commandIn;
}

드론을 쓰는 쪽은 commandPort만 알면 됩니다.

part def DeliveryService {
    part drones : Drone[1..*];
    part groundStation : GroundStation;

    interface commandLinks : CommandLink
        connect [1] groundStation.commandPort to [1..*] drones.commandPort;
}
flowchart LR
    subgraph gs["groundStation"]
        gcp(["commandPort"])
    end
    subgraph drone["drones"]
        dcp(["commandPort"])
        subgraph radio["radio"]
            up(["uplink"])
            co(["commandOut"])
        end
        subgraph fc["flightController"]
            ci(["commandIn"])
        end
    end
    gcp -- commandLinks --- dcp
    dcp -. bind .- up
    up ~~~ co
    co -- commandLine --- ci

DeliveryService는 드론의 안쪽을 가리키지 않습니다. radio를 다른 부품으로 바꾸거나 드론 안의 배선을 고쳐도, Drone의 commandPort가 그대로이면 DeliveryService의 선언은 바뀌지 않습니다.

port definition 안에 port usage를 선언하면 여러 접점을 하나로 묶을 수 있습니다. 전원선과 신호선을 한 단자에 모은 경우가 그 예입니다.

port def AvionicsPort {
    port power : ~PowerPort;
    port command : ~CommandPort;
}

KerML에서 보면

port definition은 item definition처럼 KerML의 structure이지만 item definition은 아닙니다. Systems Model Library의 Ports::Port는 Items::Item을 거치지 않고 Objects::Object를 바로 특수화합니다. port는 item도 part도 아닙니다.

SysMLKerML기준 library element
port definition (PortDefinition)StructurePorts::Port
port usage (PortUsage)structure를 type으로 갖는 FeaturePorts::ports
conjugated port definition (ConjugatedPortDefinition)conjugation의 conjugated type
interface definition (InterfaceDefinition)AssociationStructureInterfaces::Interface, binary이면 Interfaces::BinaryInterface
interface usage (InterfaceUsage)ConnectorInterfaces::interfaces, binary이면 Interfaces::binaryInterfaces

part에 선언한 port usage는 Parts::Part::ownedPorts를 subset하며, ref를 적지 않아도 referential입니다. port usage 가운데 composite인 것은 다른 port 안에 중첩한 것뿐입니다.

conjugation은 KerML Core 계층의 relationship입니다. conjugation으로 이어진 두 type 가운데 conjugated type은 original type의 feature를 모두 물려받되, in과 out을 서로 바꾸어 물려받습니다. KerML에서는 어떤 type에나 conjugation을 선언할 수 있고, 키워드 conjugates나 기호 ~로 적습니다.

struct PowerPort {
    out feature power : ElectricPower;
    feature voltage : Real;
}

struct PowerInlet conjugates PowerPort;

PowerInlet에는 in feature power와 feature voltage가 있습니다. conjugated type은 다른 type을 특수화할 수 없고, original type을 하나만 가질 수 있습니다.

SysML은 conjugation을 port definition에만 쓰고 선언 방식도 고정했습니다. port definition을 선언하면 그 namespace 안에 conjugated port definition이 함께 생기며, 그 이름은 원래 이름 앞에 ~를 붙인 것입니다. PowerPort의 짝은 PowerPort::'~PowerPort'이고, port powerIn : ~PowerPort;의 ~PowerPort는 이 qualified name의 축약 표기입니다.

Ports::Port에는 interfacingPorts라는 feature가 있어서, 어떤 port와 interface로 이어진 port를 모두 모읍니다. port를 거쳐 보낸 것이 interface의 반대쪽에 닿는다는 규칙은 library가 이 feature를 써서 정의합니다.

구문 요약

구문뜻
port def P { out item x : T; }port definition입니다.
port p : P;port usage입니다.
port p : ~P;P의 conjugated port definition을 type으로 갖는 port usage입니다.
interface def I { end a : P; end b : ~P; }interface definition입니다.
interface i : I connect x.p to y.q;type이 I인 interface usage입니다.
interface x.p to y.q;definition과 이름이 없는 interface usage입니다.
bind p = x.q;바깥 part의 port와 안쪽 part의 port가 같은 접점임을 나타냅니다.

명세에서 찾아보기

주제조항
port definition과 usageSysML 7.12.1, 7.12.2, 8.3.12, 8.4.8
conjugated port definitionSysML 7.12.3
interface definition과 usageSysML 7.14, 8.3.14, 8.4.10
Ports, Interfaces librarySysML 9.2.5, 9.2.7
conjugationKerML 7.3.2.4