001package gov.nist.secauto.oscal.lib.model;
002
003import gov.nist.secauto.metaschema.binding.model.annotations.AllowedValue;
004import gov.nist.secauto.metaschema.binding.model.annotations.AllowedValues;
005import gov.nist.secauto.metaschema.binding.model.annotations.BoundFlag;
006import gov.nist.secauto.metaschema.binding.model.annotations.Expect;
007import gov.nist.secauto.metaschema.binding.model.annotations.MetaschemaAssembly;
008import gov.nist.secauto.metaschema.binding.model.annotations.ValueConstraints;
009import gov.nist.secauto.metaschema.model.common.constraint.IConstraint;
010import gov.nist.secauto.metaschema.model.common.datatype.adapter.NonNegativeIntegerAdapter;
011import gov.nist.secauto.metaschema.model.common.datatype.adapter.TokenAdapter;
012import java.lang.Override;
013import java.lang.String;
014import java.math.BigInteger;
015import org.apache.commons.lang3.builder.MultilineRecursiveToStringStyle;
016import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
017
018/**
019 * Where applicable this is the IPv4 port range on which the service operates.
020 */
021@MetaschemaAssembly(
022    formalName = "Port Range",
023    description = "Where applicable this is the IPv4 port range on which the service operates.",
024    name = "port-range",
025    metaschema = OscalImplementationCommonMetaschema.class,
026    remarks = "To be validated as a natural number (integer \\>= 1). A single port uses the same value for start and end. Use multiple 'port-range' entries for non-contiguous ranges."
027)
028@ValueConstraints(
029    expect = {
030        @Expect(id = "port-range-start-and-end-not-specified", level = IConstraint.Level.WARNING, test = "exists(@start) and exists(@end)", message = "If a protocol is defined, it should include a start and end port range. To define a single port, the start and end should be the same value."),
031        @Expect(id = "port-range-start-specified-with-no-end", level = IConstraint.Level.WARNING, test = "exists(@start) and not(exists(@end))", message = "A start port exists, but an end point does not. To define a single port, the start and end should be the same value."),
032        @Expect(id = "port-range-end-specified-with-no-start", level = IConstraint.Level.WARNING, test = "not(exists(@start)) and exists(@end)", message = "An end point exists, but a start port does not. To define a single port, the start and end should be the same value."),
033        @Expect(id = "port-range-end-date-is-before-start-date", level = IConstraint.Level.WARNING, test = "@start <= @end", message = "The port range specified has an end port that is less than the start port.")
034    }
035)
036public class PortRange {
037  @BoundFlag(
038      formalName = "Start",
039      description = "Indicates the starting port number in a port range",
040      useName = "start",
041      typeAdapter = NonNegativeIntegerAdapter.class,
042      remarks = "Should be a number within a permitted range"
043  )
044  private BigInteger _start;
045
046  @BoundFlag(
047      formalName = "End",
048      description = "Indicates the ending port number in a port range",
049      useName = "end",
050      typeAdapter = NonNegativeIntegerAdapter.class,
051      remarks = "Should be a number within a permitted range"
052  )
053  private BigInteger _end;
054
055  @BoundFlag(
056      formalName = "Transport",
057      description = "Indicates the transport type.",
058      useName = "transport",
059      typeAdapter = TokenAdapter.class
060  )
061  @ValueConstraints(
062      allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, values = {@AllowedValue(value = "TCP", description = "Transmission Control Protocol"), @AllowedValue(value = "UDP", description = "User Datagram Protocol")})
063  )
064  private String _transport;
065
066  public PortRange() {
067  }
068
069  public BigInteger getStart() {
070    return _start;
071  }
072
073  public void setStart(BigInteger value) {
074    _start = value;
075  }
076
077  public BigInteger getEnd() {
078    return _end;
079  }
080
081  public void setEnd(BigInteger value) {
082    _end = value;
083  }
084
085  public String getTransport() {
086    return _transport;
087  }
088
089  public void setTransport(String value) {
090    _transport = value;
091  }
092
093  @Override
094  public String toString() {
095    return new ReflectionToStringBuilder(this, MultilineRecursiveToStringStyle.MULTI_LINE_STYLE).toString();
096  }
097}