use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.ActionsBuilder in project openflowplugin by opendaylight.
the class ApplyActionsInstructionDeserializer method deserialize.
@Override
public Instruction deserialize(ByteBuf input) {
final InstructionBuilder builder = new InstructionBuilder();
input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
int instructionLength = input.readUnsignedShort();
input.skipBytes(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION);
ApplyActionsCaseBuilder caseBuilder = new ApplyActionsCaseBuilder();
ApplyActionsBuilder actionsBuilder = new ApplyActionsBuilder();
actionsBuilder.setAction(deserializeActions(input, instructionLength));
caseBuilder.setApplyActions(actionsBuilder.build());
builder.setInstructionChoice(caseBuilder.build());
return builder.build();
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.ActionsBuilder in project openflowplugin by opendaylight.
the class WriteActionsInstructionDeserializer method deserialize.
@Override
public Instruction deserialize(ByteBuf input) {
final InstructionBuilder builder = new InstructionBuilder();
input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
int instructionLength = input.readUnsignedShort();
input.skipBytes(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION);
WriteActionsCaseBuilder caseBuilder = new WriteActionsCaseBuilder();
WriteActionsBuilder actionsBuilder = new WriteActionsBuilder();
actionsBuilder.setAction(deserializeActions(input, instructionLength));
caseBuilder.setWriteActions(actionsBuilder.build());
builder.setInstructionChoice(caseBuilder.build());
return builder.build();
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.ActionsBuilder in project openflowplugin by opendaylight.
the class FlowModInputMessageFactoryTest method testFlowModInputMessageFactory.
/**
* Testing of {@link FlowModInputMessageFactory} for correct translation from POJO.
*/
@Test
public void testFlowModInputMessageFactory() throws Exception {
FlowModInputBuilder builder = new FlowModInputBuilder();
BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
byte[] cookie = new byte[] { (byte) 0xFF, 0x01, 0x04, 0x01, 0x06, 0x00, 0x07, 0x01 };
builder.setCookie(new BigInteger(1, cookie));
byte[] cookieMask = new byte[] { (byte) 0xFF, 0x05, 0x00, 0x00, 0x09, 0x30, 0x00, 0x30 };
builder.setCookieMask(new BigInteger(1, cookieMask));
builder.setTableId(new TableId(65L));
builder.setCommand(FlowModCommand.forValue(2));
builder.setIdleTimeout(12);
builder.setHardTimeout(0);
builder.setPriority(126);
builder.setBufferId(2L);
builder.setOutPort(new PortNumber(4422L));
builder.setOutGroup(98L);
builder.setFlags(new FlowModFlags(true, false, true, false, true));
MatchBuilder matchBuilder = new MatchBuilder();
matchBuilder.setType(OxmMatchType.class);
final List<MatchEntry> entries = new ArrayList<>();
MatchEntryBuilder entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(InPhyPort.class);
entriesBuilder.setHasMask(false);
InPhyPortCaseBuilder inPhyPortCaseBuilder = new InPhyPortCaseBuilder();
InPhyPortBuilder inPhyPortBuilder = new InPhyPortBuilder();
inPhyPortBuilder.setPortNumber(new PortNumber(42L));
inPhyPortCaseBuilder.setInPhyPort(inPhyPortBuilder.build());
entriesBuilder.setMatchEntryValue(inPhyPortCaseBuilder.build());
entries.add(entriesBuilder.build());
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(IpEcn.class);
entriesBuilder.setHasMask(false);
IpEcnCaseBuilder ipEcnCaseBuilder = new IpEcnCaseBuilder();
IpEcnBuilder ipEcnBuilder = new IpEcnBuilder();
ipEcnBuilder.setEcn((short) 4);
ipEcnCaseBuilder.setIpEcn(ipEcnBuilder.build());
entriesBuilder.setMatchEntryValue(ipEcnCaseBuilder.build());
entries.add(entriesBuilder.build());
matchBuilder.setMatchEntry(entries);
builder.setMatch(matchBuilder.build());
final List<Instruction> instructions = new ArrayList<>();
InstructionBuilder insBuilder = new InstructionBuilder();
GotoTableCaseBuilder goToCaseBuilder = new GotoTableCaseBuilder();
GotoTableBuilder instructionBuilder = new GotoTableBuilder();
instructionBuilder.setTableId((short) 43);
goToCaseBuilder.setGotoTable(instructionBuilder.build());
insBuilder.setInstructionChoice(goToCaseBuilder.build());
instructions.add(insBuilder.build());
WriteMetadataCaseBuilder metadataCaseBuilder = new WriteMetadataCaseBuilder();
WriteMetadataBuilder metadataBuilder = new WriteMetadataBuilder();
metadataBuilder.setMetadata(cookie);
metadataBuilder.setMetadataMask(cookieMask);
metadataCaseBuilder.setWriteMetadata(metadataBuilder.build());
insBuilder.setInstructionChoice(metadataCaseBuilder.build());
instructions.add(insBuilder.build());
insBuilder = new InstructionBuilder();
final ApplyActionsCaseBuilder applyActionsCaseBuilder = new ApplyActionsCaseBuilder();
final ApplyActionsBuilder actionsBuilder = new ApplyActionsBuilder();
final List<Action> actions = new ArrayList<>();
final ActionBuilder actionBuilder = new ActionBuilder();
OutputActionCaseBuilder caseBuilder = new OutputActionCaseBuilder();
OutputActionBuilder outputBuilder = new OutputActionBuilder();
outputBuilder.setPort(new PortNumber(42L));
outputBuilder.setMaxLength(52);
caseBuilder.setOutputAction(outputBuilder.build());
actionBuilder.setActionChoice(caseBuilder.build());
actions.add(actionBuilder.build());
actionsBuilder.setAction(actions);
applyActionsCaseBuilder.setApplyActions(actionsBuilder.build());
insBuilder.setInstructionChoice(applyActionsCaseBuilder.build());
instructions.add(insBuilder.build());
builder.setInstruction(instructions);
final FlowModInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
// simulate parent message
out.writeInt(1);
out.writeZero(2);
out.writeShort(3);
flowModFactory.serialize(message, out);
// read parent message
out.readInt();
out.skipBytes(2);
out.readShort();
BufferHelper.checkHeaderV13(out, (byte) 14, 128);
cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
out.readBytes(cookie);
Assert.assertEquals("Wrong cookie", message.getCookie(), new BigInteger(1, cookie));
cookieMask = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
out.readBytes(cookieMask);
Assert.assertEquals("Wrong cookieMask", message.getCookieMask(), new BigInteger(1, cookieMask));
Assert.assertEquals("Wrong tableId", message.getTableId().getValue().intValue(), out.readUnsignedByte());
Assert.assertEquals("Wrong command", message.getCommand().getIntValue(), out.readUnsignedByte());
Assert.assertEquals("Wrong idleTimeOut", message.getIdleTimeout().intValue(), out.readShort());
Assert.assertEquals("Wrong hardTimeOut", message.getHardTimeout().intValue(), out.readShort());
Assert.assertEquals("Wrong priority", message.getPriority().intValue(), out.readUnsignedShort());
Assert.assertEquals("Wrong bufferId", message.getBufferId().intValue(), out.readUnsignedInt());
Assert.assertEquals("Wrong outPort", message.getOutPort().getValue().intValue(), out.readUnsignedInt());
Assert.assertEquals("Wrong outGroup", message.getOutGroup().intValue(), out.readUnsignedInt());
Assert.assertEquals("Wrong flags", message.getFlags(), createFlowModFlagsFromBitmap(out.readUnsignedShort()));
out.skipBytes(PADDING_IN_FLOW_MOD_MESSAGE);
Assert.assertEquals("Wrong match type", 1, out.readUnsignedShort());
out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
Assert.assertEquals("Wrong oxm class", 0x8000, out.readUnsignedShort());
short fieldAndMask = out.readUnsignedByte();
Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1);
Assert.assertEquals("Wrong oxm field", 1, fieldAndMask >> 1);
out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
Assert.assertEquals("Wrong oxm value", 42, out.readUnsignedInt());
Assert.assertEquals("Wrong oxm class", 0x8000, out.readUnsignedShort());
fieldAndMask = out.readUnsignedByte();
Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1);
Assert.assertEquals("Wrong oxm field", 9, fieldAndMask >> 1);
out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
Assert.assertEquals("Wrong oxm value", 4, out.readUnsignedByte());
out.skipBytes(7);
Assert.assertEquals("Wrong instruction type", 1, out.readUnsignedShort());
out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
Assert.assertEquals("Wrong instruction value", 43, out.readUnsignedByte());
out.skipBytes(3);
Assert.assertEquals("Wrong instruction type", 2, out.readUnsignedShort());
out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
out.skipBytes(EncodeConstants.SIZE_OF_INT_IN_BYTES);
byte[] cookieRead = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
out.readBytes(cookieRead);
byte[] cookieMaskRead = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
out.readBytes(cookieMaskRead);
Assert.assertArrayEquals("Wrong metadata", cookie, cookieRead);
Assert.assertArrayEquals("Wrong metadata mask", cookieMask, cookieMaskRead);
Assert.assertEquals("Wrong instruction type", 4, out.readUnsignedShort());
Assert.assertEquals("Wrong instruction length", 24, out.readUnsignedShort());
out.skipBytes(4);
Assert.assertEquals("Wrong action type", 0, out.readUnsignedShort());
Assert.assertEquals("Wrong action length", 16, out.readUnsignedShort());
Assert.assertEquals("Wrong port", 42, out.readUnsignedInt());
Assert.assertEquals("Wrong max-length", 52, out.readUnsignedShort());
out.skipBytes(6);
Assert.assertTrue("Unread data", out.readableBytes() == 0);
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.ActionsBuilder in project netvirt by opendaylight.
the class FlowClassifierTranslator method buildAcl.
public static Acl buildAcl(SfcFlowClassifier flowClassifier, String sfpName) {
LOG.info("OpenStack Networking SFC pushed Flow classifier : {}", flowClassifier);
AclBuilder aclBuilder = new AclBuilder();
AceBuilder aceBuilder = new AceBuilder();
ActionsBuilder actionsBuilder = new ActionsBuilder();
RedirectToSfcBuilder redirectToSfcBuilder = new RedirectToSfcBuilder();
NeutronPortsBuilder neutronPortsBuilder = new NeutronPortsBuilder();
AceIpBuilder aceIpBuilder = new AceIpBuilder();
DestinationPortRangeBuilder destinationPortRange = new DestinationPortRangeBuilder();
SourcePortRangeBuilder sourcePortRangeBuilder = new SourcePortRangeBuilder();
if (flowClassifier.getUuid() != null) {
if (flowClassifier.getName() != null) {
aclBuilder.setAclName(flowClassifier.getUuid().getValue() + "_" + flowClassifier.getName());
} else {
aclBuilder.setAclName(flowClassifier.getUuid().getValue());
}
}
if (flowClassifier.getEthertype() != null) {
IpPrefix sourceIp = null;
IpPrefix destinationIp = null;
if (flowClassifier.getSourceIpPrefix() != null) {
sourceIp = flowClassifier.getSourceIpPrefix();
}
if (flowClassifier.getDestinationIpPrefix() != null) {
destinationIp = flowClassifier.getDestinationIpPrefix();
}
if (flowClassifier.getEthertype() == EthertypeV4.class) {
AceIpv4Builder aceIpv4Builder = new AceIpv4Builder();
if (sourceIp != null && sourceIp.getIpv4Prefix() != null) {
aceIpv4Builder.setSourceIpv4Network(sourceIp.getIpv4Prefix());
}
if (destinationIp != null && destinationIp.getIpv4Prefix() != null) {
aceIpv4Builder.setDestinationIpv4Network(destinationIp.getIpv4Prefix());
}
aceIpBuilder.setAceIpVersion(aceIpv4Builder.build());
aclBuilder.setAclType(Ipv4Acl.class);
}
if (flowClassifier.getEthertype() == EthertypeV6.class) {
AceIpv6Builder aceIpv6Builder = new AceIpv6Builder();
if (sourceIp != null && sourceIp.getIpv6Prefix() != null) {
aceIpv6Builder.setSourceIpv6Network(sourceIp.getIpv6Prefix());
}
if (sourceIp != null && destinationIp.getIpv6Prefix() != null) {
aceIpv6Builder.setDestinationIpv6Network(destinationIp.getIpv6Prefix());
}
aceIpBuilder.setAceIpVersion(aceIpv6Builder.build());
aclBuilder.setAclType(Ipv6Acl.class);
}
}
if (flowClassifier.getProtocol() != null) {
if (flowClassifier.getProtocol() == ProtocolTcp.class) {
aceIpBuilder.setProtocol(PROTO_TCP);
}
if (flowClassifier.getProtocol() == ProtocolUdp.class) {
aceIpBuilder.setProtocol(PROTO_UDP);
}
}
if (flowClassifier.getSourcePortRangeMin() != null) {
sourcePortRangeBuilder.setLowerPort(new PortNumber(flowClassifier.getSourcePortRangeMin()));
// set source port range only if lower port is specified as it is a mandatory parameter in acl model
aceIpBuilder.setSourcePortRange(sourcePortRangeBuilder.build());
}
if (flowClassifier.getSourcePortRangeMax() != null) {
sourcePortRangeBuilder.setUpperPort(new PortNumber(flowClassifier.getSourcePortRangeMax()));
}
if (flowClassifier.getDestinationPortRangeMin() != null) {
destinationPortRange.setLowerPort(new PortNumber(flowClassifier.getDestinationPortRangeMin()));
// set destination port range only if lower port is specified as it is a mandatory parameter in acl model
aceIpBuilder.setDestinationPortRange(destinationPortRange.build());
}
if (flowClassifier.getDestinationPortRangeMax() != null) {
destinationPortRange.setUpperPort(new PortNumber(flowClassifier.getDestinationPortRangeMax()));
}
if (flowClassifier.getLogicalSourcePort() != null) {
neutronPortsBuilder.setSourcePortUuid(flowClassifier.getLogicalSourcePort().getValue());
}
if (flowClassifier.getLogicalDestinationPort() != null) {
neutronPortsBuilder.setDestinationPortUuid(flowClassifier.getLogicalDestinationPort().getValue());
}
// currently not supported.
// if (flowClassifier.getL7Parameter() != null) {
// }
MatchesBuilder matchesBuilder = new MatchesBuilder();
matchesBuilder.setAceType(aceIpBuilder.build());
matchesBuilder.addAugmentation(NeutronPorts.class, neutronPortsBuilder.build());
// Set redirect-to-rsp action if rsp name is provided
if (sfpName != null) {
redirectToSfcBuilder.setSfpName(sfpName);
actionsBuilder.addAugmentation(RedirectToSfc.class, redirectToSfcBuilder.build());
aceBuilder.setActions(actionsBuilder.build());
}
aceBuilder.setMatches(matchesBuilder.build());
// OpenStack networking-sfc don't pass action information
// with flow classifier. It need to be determined using the
// Port Chain data and then flow calssifier need to be updated
// with the actions.
aceBuilder.setRuleName(aclBuilder.getAclName() + RULE);
aceBuilder.setKey(new AceKey(aceBuilder.getRuleName()));
ArrayList<Ace> aceList = new ArrayList<>();
aceList.add(aceBuilder.build());
AccessListEntriesBuilder accessListEntriesBuilder = new AccessListEntriesBuilder();
accessListEntriesBuilder.setAce(aceList);
aclBuilder.setAccessListEntries(accessListEntriesBuilder.build());
aclBuilder.setKey(new AclKey(aclBuilder.getAclName(), aclBuilder.getAclType()));
LOG.info("Translated ACL Flow classfier : {}", aclBuilder.toString());
return aclBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.ActionsBuilder in project netvirt by opendaylight.
the class NeutronSecurityRuleListener method toAceBuilder.
private AceBuilder toAceBuilder(SecurityRule securityRule) {
AceIpBuilder aceIpBuilder = new AceIpBuilder();
SecurityRuleAttrBuilder securityRuleAttrBuilder = new SecurityRuleAttrBuilder();
DestinationPortRangeBuilder destinationPortRangeBuilder = new DestinationPortRangeBuilder();
boolean isDirectionIngress = false;
if (securityRule.getDirection() != null) {
securityRuleAttrBuilder.setDirection(DIRECTION_MAP.get(securityRule.getDirection()));
isDirectionIngress = securityRule.getDirection().equals(DirectionIngress.class);
}
if (securityRule.getPortRangeMax() != null) {
destinationPortRangeBuilder.setUpperPort(new PortNumber(securityRule.getPortRangeMax()));
}
if (securityRule.getPortRangeMin() != null) {
destinationPortRangeBuilder.setLowerPort(new PortNumber(securityRule.getPortRangeMin()));
// set destination port range if lower port is specified as it is mandatory parameter in acl model
aceIpBuilder.setDestinationPortRange(destinationPortRangeBuilder.build());
}
aceIpBuilder = handleRemoteIpPrefix(securityRule, aceIpBuilder, isDirectionIngress);
if (securityRule.getRemoteGroupId() != null) {
securityRuleAttrBuilder.setRemoteGroupId(securityRule.getRemoteGroupId());
}
if (securityRule.getProtocol() != null) {
SecurityRuleAttributes.Protocol protocol = securityRule.getProtocol();
if (protocol.getUint8() != null) {
// uint8
aceIpBuilder.setProtocol(protocol.getUint8());
} else {
// symbolic protocol name
aceIpBuilder.setProtocol(PROTOCOL_MAP.get(protocol.getIdentityref()));
}
}
MatchesBuilder matchesBuilder = new MatchesBuilder();
matchesBuilder.setAceType(aceIpBuilder.build());
// set acl action as permit for the security rule
ActionsBuilder actionsBuilder = new ActionsBuilder();
actionsBuilder.setPacketHandling(new PermitBuilder().setPermit(true).build());
AceBuilder aceBuilder = new AceBuilder();
aceBuilder.setKey(new AceKey(securityRule.getUuid().getValue()));
aceBuilder.setRuleName(securityRule.getUuid().getValue());
aceBuilder.setMatches(matchesBuilder.build());
aceBuilder.setActions(actionsBuilder.build());
aceBuilder.addAugmentation(SecurityRuleAttr.class, securityRuleAttrBuilder.build());
return aceBuilder;
}
Aggregations