use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber in project netvirt by opendaylight.
the class AclMatches method addIpProtocolMatch.
private void addIpProtocolMatch(AceIp aceIp) {
// Match on IP
setIpv4EtherType();
IpMatchBuilder ipMatch = new IpMatchBuilder();
ipMatch.setIpProtocol(aceIp.getProtocol());
matchBuilder.setIpMatch(mergeIpMatch(matchBuilder, ipMatch));
// TODO Ranges are not supported yet
int srcPort = 0;
if (aceIp.getSourcePortRange() != null && aceIp.getSourcePortRange().getLowerPort() != null) {
srcPort = aceIp.getSourcePortRange().getLowerPort().getValue();
}
int dstPort = 0;
if (aceIp.getDestinationPortRange() != null && aceIp.getDestinationPortRange().getLowerPort() != null) {
dstPort = aceIp.getDestinationPortRange().getLowerPort().getValue();
}
// Match on a TCP/UDP src/dst port
if (aceIp.getProtocol() == IPProtocols.TCP.shortValue()) {
TcpMatchBuilder tcpMatch = new TcpMatchBuilder();
if (srcPort != 0) {
tcpMatch.setTcpSourcePort(new PortNumber(srcPort));
}
if (dstPort != 0) {
tcpMatch.setTcpDestinationPort(new PortNumber(dstPort));
}
if (srcPort != 0 || dstPort != 0) {
matchBuilder.setLayer4Match(tcpMatch.build());
}
} else if (aceIp.getProtocol() == IPProtocols.UDP.shortValue()) {
UdpMatchBuilder udpMatch = new UdpMatchBuilder();
if (srcPort != 0) {
udpMatch.setUdpSourcePort(new PortNumber(srcPort));
}
if (dstPort != 0) {
udpMatch.setUdpDestinationPort(new PortNumber(dstPort));
}
if (srcPort != 0 || dstPort != 0) {
matchBuilder.setLayer4Match(udpMatch.build());
}
}
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber in project netvirt by opendaylight.
the class AclMatchesTest method invertIpv6MatchTest.
@Test
public void invertIpv6MatchTest() {
AceIpBuilder aceIpBuilder = new AceIpBuilder();
aceIpBuilder.setProtocol(IPProtocols.TCP.shortValue());
aceIpBuilder.setDscp(new Dscp(DSCP_VALUE));
SourcePortRangeBuilder srcPortRange = new SourcePortRangeBuilder();
srcPortRange.setLowerPort(new PortNumber(TCP_SRC_LOWER_PORT));
srcPortRange.setUpperPort(new PortNumber(TCP_SRC_UPPER_PORT));
SourcePortRange sourcePortRange = srcPortRange.build();
aceIpBuilder.setSourcePortRange(sourcePortRange);
DestinationPortRangeBuilder dstPortRange = new DestinationPortRangeBuilder();
dstPortRange.setLowerPort(new PortNumber(TCP_DST_LOWER_PORT));
dstPortRange.setUpperPort(new PortNumber(TCP_DST_UPPER_PORT));
DestinationPortRange destinationPortRange = dstPortRange.build();
aceIpBuilder.setDestinationPortRange(destinationPortRange);
AceIpv6Builder aceIpv6Builder = new AceIpv6Builder();
aceIpv6Builder.setDestinationIpv6Network(new Ipv6Prefix(IPV6_DST_STR));
aceIpv6Builder.setSourceIpv6Network(new Ipv6Prefix(IPV6_SRC_STR));
AceIpv6 aceIpv6 = aceIpv6Builder.build();
aceIpBuilder.setAceIpVersion(aceIpv6);
MatchesBuilder matchesBuilder = new MatchesBuilder();
AceIp aceIp = aceIpBuilder.build();
matchesBuilder.setAceType(aceIp);
Matches matches = matchesBuilder.build();
Matches invertedMatches = AclMatches.invertMatches(matches);
assertNotEquals(matches, invertedMatches);
AceIp invertedAceIp = (AceIp) invertedMatches.getAceType();
assertEquals(invertedAceIp.getDscp(), aceIp.getDscp());
assertEquals(invertedAceIp.getProtocol(), aceIp.getProtocol());
DestinationPortRange invertedDestinationPortRange = invertedAceIp.getDestinationPortRange();
assertEquals(invertedDestinationPortRange.getLowerPort(), sourcePortRange.getLowerPort());
assertEquals(invertedDestinationPortRange.getUpperPort(), sourcePortRange.getUpperPort());
SourcePortRange invertedSourcePortRange = invertedAceIp.getSourcePortRange();
assertEquals(invertedSourcePortRange.getLowerPort(), destinationPortRange.getLowerPort());
assertEquals(invertedSourcePortRange.getUpperPort(), destinationPortRange.getUpperPort());
AceIpv6 invertedAceIpv6 = (AceIpv6) invertedAceIp.getAceIpVersion();
assertEquals(invertedAceIpv6.getDestinationIpv6Network(), aceIpv6.getSourceIpv6Network());
assertEquals(invertedAceIpv6.getSourceIpv6Network(), aceIpv6.getDestinationIpv6Network());
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber in project netvirt by opendaylight.
the class StatisticsImpl method getNodeConnectorResult.
private boolean getNodeConnectorResult(List<CounterResult> counters, BigInteger dpId, String portNumber) {
CounterResultDataStructure counterResultDS = counterRetriever.getNodeConnectorCountersDirect(new NodeId(CountersUtils.getNodeId(dpId)), new NodeConnectorId(CountersUtils.getNodeConnectorId(dpId, portNumber)));
if (counterResultDS == null) {
return false;
}
CounterResultBuilder crb = new CounterResultBuilder();
String resultId = CountersUtils.getNodeConnectorId(dpId, portNumber);
crb.setId(resultId);
createGroups(counters, counterResultDS, crb, resultId);
return !counters.isEmpty();
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber in project netvirt by opendaylight.
the class StatisticsImpl method getNodeConnectorCounters.
@Override
@SuppressWarnings("checkstyle:illegalCatch")
public Future<RpcResult<GetNodeConnectorCountersOutput>> getNodeConnectorCounters(GetNodeConnectorCountersInput input) {
String portId = input.getPortId();
LOG.trace("getting port counters of port {}", portId);
Interface interfaceState = InterfaceUtils.getInterfaceStateFromOperDS(db, portId);
if (interfaceState == null) {
LOG.warn("trying to get counters for non exist port {}", portId);
return RpcResultBuilder.<GetNodeConnectorCountersOutput>failed().buildFuture();
}
BigInteger dpId = InterfaceUtils.getDpIdFromInterface(interfaceState);
if (interfaceState.getLowerLayerIf() == null || interfaceState.getLowerLayerIf().isEmpty()) {
LOG.warn("Lower layer if wasn't found for port {}", portId);
return RpcResultBuilder.<GetNodeConnectorCountersOutput>failed().buildFuture();
}
String portNumber = interfaceState.getLowerLayerIf().get(0);
portNumber = portNumber.split(":")[2];
List<CounterResult> counterResults = new ArrayList<>();
try {
if (!getNodeConnectorResult(counterResults, dpId, portNumber)) {
StatisticsPluginImplCounters.failed_getting_node_connector_counters.inc();
return RpcResultBuilder.<GetNodeConnectorCountersOutput>failed().withError(ErrorType.APPLICATION, "failed to get port counters").buildFuture();
}
} catch (RuntimeException e) {
LOG.warn("failed to get counter result for port {}", portId, e);
}
GetNodeConnectorCountersOutputBuilder gpcob = new GetNodeConnectorCountersOutputBuilder();
gpcob.setCounterResult(counterResults);
return RpcResultBuilder.success(gpcob.build()).buildFuture();
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber in project netvirt by opendaylight.
the class AclServiceTestBase method newMatch.
// TODO refactor this instead of stealing it from org.opendaylight.netvirt.neutronvpn.NeutronSecurityRuleListener
protected Matches newMatch(int srcLowerPort, int srcUpperPort, int destLowerPort, int destupperPort, int srcRemoteIpPrefix, int dstRemoteIpPrefix, short protocol) {
AceIpBuilder aceIpBuilder = new AceIpBuilder();
if (destLowerPort != -1) {
DestinationPortRangeBuilder destinationPortRangeBuilder = new DestinationPortRangeBuilder();
destinationPortRangeBuilder.setLowerPort(new PortNumber(destLowerPort));
destinationPortRangeBuilder.setUpperPort(new PortNumber(destupperPort));
aceIpBuilder.setDestinationPortRange(destinationPortRangeBuilder.build());
}
AceIpv4Builder aceIpv4Builder = new AceIpv4Builder();
if (srcRemoteIpPrefix == AclConstants.SOURCE_REMOTE_IP_PREFIX_SPECIFIED) {
aceIpv4Builder.setSourceIpv4Network(new Ipv4Prefix(AclConstants.IPV4_ALL_NETWORK));
}
if (dstRemoteIpPrefix == AclConstants.DEST_REMOTE_IP_PREFIX_SPECIFIED) {
aceIpv4Builder.setSourceIpv4Network(new Ipv4Prefix(AclConstants.IPV4_ALL_NETWORK));
}
if (protocol != -1) {
aceIpBuilder.setProtocol(protocol);
}
aceIpBuilder.setAceIpVersion(aceIpv4Builder.build());
MatchesBuilder matchesBuilder = new MatchesBuilder();
matchesBuilder.setAceType(aceIpBuilder.build());
return matchesBuilder.build();
}
Aggregations