use of org.opendaylight.yangtools.yang.common.Uint8 in project netvirt by opendaylight.
the class DisplayAclDataCaches method printAcl.
private void printAcl(String aclId, Acl acl) {
session.getConsole().println();
session.getConsole().println(ACL_HEADER + String.format("%-32s ", aclId));
if (null != acl.getAccessListEntries() && null != acl.getAccessListEntries().getAce()) {
printHeader(ACL_ENTRIES_HEADERS, ACL_ENTRIES_HEADER_LINE);
List<Ace> aceList = acl.getAccessListEntries().getAce();
for (Ace ace : aceList) {
LOG.info("ace data: {}", ace);
SecurityRuleAttr aceAttr = getAccessListAttributes(ace);
Class<? extends DirectionBase> aceAttrDirection = aceAttr.getDirection();
AceIp aceIp = (AceIp) ace.getMatches().getAceType();
AceIpVersion ipVersion = aceIp.getAceIpVersion();
Uint8 protoNum = aceIp.getProtocol();
String protocol = "Any";
if (null != protoNum) {
protocol = protoMap.get(protoNum.toString());
protocol = (protocol == null) ? protoNum.toString() : protocol;
}
String ipVer = "";
String direction = DirectionEgress.class.equals(aceAttrDirection) ? "Egress" : "Ingress";
String ipPrefix = " -- ";
if (null != ipVersion && ipVersion instanceof AceIpv4) {
ipVer = "IPv4";
Ipv4Prefix srcNetwork = ((AceIpv4) ipVersion).getSourceIpv4Network();
if (null != srcNetwork) {
ipPrefix = srcNetwork.getValue();
}
} else if (null != ipVersion && ipVersion instanceof AceIpv6) {
ipVer = "IPv6";
Ipv6Prefix srcNetwork = ((AceIpv6) ipVersion).getSourceIpv6Network();
if (null != srcNetwork) {
ipPrefix = srcNetwork.getValue();
}
}
String remoteGroupId = "-";
if (aceAttr.getRemoteGroupId() != null) {
remoteGroupId = aceAttr.getRemoteGroupId().getValue();
ipPrefix = "-";
}
String prefixAndRemoteId = ipPrefix + " / " + remoteGroupId;
session.getConsole().print(String.format(ACE_ENTRIES_FORMAT_STRING, ace.key().getRuleName(), direction, protocol, ipVer, prefixAndRemoteId));
}
}
session.getConsole().println();
}
use of org.opendaylight.yangtools.yang.common.Uint8 in project bgpcep by opendaylight.
the class OpaqueUtil method parseOpaque.
public static Opaque parseOpaque(final ByteBuf buffer) {
final Uint8 type = ByteBufUtils.readUint8(buffer);
final OpaqueValueBuilder builder = new OpaqueValueBuilder();
switch(type.toJava()) {
case GENERIC_LSP_IDENTIFIER:
builder.setOpaque(buildOpaqueValue(buffer));
break;
case EXTENDED_TYPE:
buildExtended(builder, buffer);
break;
default:
final int length = buffer.readUnsignedShort();
buffer.skipBytes(length);
LOG.debug("Skipping parsing of Opaque Value {}", buffer);
return null;
}
return builder.setOpaqueType(type).build();
}
use of org.opendaylight.yangtools.yang.common.Uint8 in project bgpcep by opendaylight.
the class FlowspecIpv4NlriParserHelper method createProtocolsIps.
private static List<ProtocolIps> createProtocolsIps(final UnkeyedListNode protocolIpsData) {
final List<ProtocolIps> protocolIps = new ArrayList<>();
for (final UnkeyedListEntryNode node : protocolIpsData.body()) {
final ProtocolIpsBuilder ipsBuilder = new ProtocolIpsBuilder();
node.findChildByArg(AbstractFlowspecNlriParser.OP_NID).ifPresent(dataContainerChild -> ipsBuilder.setOp(NumericOneByteOperandParser.INSTANCE.create((Set<String>) dataContainerChild.body())));
node.findChildByArg(AbstractFlowspecNlriParser.VALUE_NID).ifPresent(dataContainerChild -> ipsBuilder.setValue((Uint8) dataContainerChild.body()));
protocolIps.add(ipsBuilder.build());
}
return protocolIps;
}
use of org.opendaylight.yangtools.yang.common.Uint8 in project bgpcep by opendaylight.
the class BGPNotificationMessageParser method parseMessageBody.
/**
* Parses BGP Notification message to bytes.
*
* @param body ByteBuf to be parsed
* @param messageLength the length of the message
* @return {@link Notify} which represents BGP notification message
* @throws BGPDocumentedException if parsing goes wrong
*/
@Override
public Notify parseMessageBody(final ByteBuf body, final int messageLength, final PeerSpecificParserConstraint constraint) throws BGPDocumentedException {
checkArgument(body != null, "Buffer cannot be null.");
if (body.readableBytes() < ERROR_SIZE) {
throw BGPDocumentedException.badMessageLength("Notification message too small.", messageLength);
}
final Uint8 errorCode = Uint8.valueOf(body.readUnsignedByte());
final Uint8 errorSubcode = Uint8.valueOf(body.readUnsignedByte());
final NotifyBuilder builder = new NotifyBuilder().setErrorCode(errorCode).setErrorSubcode(errorSubcode);
if (body.isReadable()) {
builder.setData(ByteArray.readAllBytes(body));
}
final Notify result = builder.build();
final BGPError err = BGPError.forValue(errorCode, errorSubcode);
if (LOG.isDebugEnabled()) {
LOG.debug("BGP Notification message was parsed: err = {}, data = {}.", err, Arrays.toString(result.getData()));
}
return result;
}
use of org.opendaylight.yangtools.yang.common.Uint8 in project bgpcep by opendaylight.
the class PCEPOpenObjectParser method parseObject.
@Override
public Object parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Cannot be null or empty.");
final int versionValue = ByteArray.copyBitsRange(bytes.readByte(), VERSION_SF_OFFSET, VERSION_SF_LENGTH);
final short keepalive = bytes.readUnsignedByte();
final short deadTimer = bytes.readUnsignedByte();
final Uint8 sessionId = ByteBufUtils.readUint8(bytes);
final TlvsBuilder tbuilder = new TlvsBuilder();
parseTlvs(tbuilder, bytes.slice());
final OpenBuilder builder = new OpenBuilder().setVersion(new ProtocolVersion(Uint8.valueOf(versionValue))).setProcessingRule(header.getProcessingRule()).setIgnore(header.getIgnore()).setKeepalive(Uint8.valueOf(keepalive)).setSessionId(sessionId).setTlvs(tbuilder.build());
if (keepalive == 0) {
builder.setDeadTimer(Uint8.ZERO);
} else {
builder.setDeadTimer(Uint8.valueOf(deadTimer));
}
final Open obj = builder.build();
if (versionValue != PCEP_VERSION) {
// TODO: Should we move this check into the negotiator
LOG.debug("Unsupported PCEP version {}", versionValue);
return new UnknownObject(PCEPErrors.PCEP_VERSION_NOT_SUPPORTED, obj);
}
return obj;
}
Aggregations