List of usage examples for com.google.common.net InetAddresses coerceToInteger
public static int coerceToInteger(InetAddress ip)
From source file:org.opendaylight.faas.fabrics.vxlan.adapters.ovs.pipeline.PipelineL2Forwarding.java
public void programSfcTunnelOut(Long dpid, Long segmentationId, Long OFSfcTunPort, String attachedMac, IpAddress dstVmVtepIp, boolean isWriteFlow) { String nodeName = OPENFLOW + dpid; MatchBuilder matchBuilder = new MatchBuilder(); NodeBuilder nodeBuilder = createNodeBuilder(nodeName); FlowBuilder flowBuilder = new FlowBuilder(); // Create the OF Match using MatchBuilder OfMatchUtils.addNxRegMatch(matchBuilder, new OfMatchUtils.RegMatch(PipelineAclHandler.REG_SFC_FIELD, PipelineAclHandler.REG_VALUE_SFC_REDIRECT)); flowBuilder.setMatch(OfMatchUtils/*from w w w . ja v a 2s.c o m*/ .createTunnelIDMatch(matchBuilder, BigInteger.valueOf(segmentationId.longValue())).build()); flowBuilder.setMatch(OfMatchUtils.createDestEthMatch(matchBuilder, attachedMac, "").build()); flowBuilder.setMatch(matchBuilder.build()); String flowId = "SfcTunnelOut_" + segmentationId + "_" + OFSfcTunPort + "_" + attachedMac + "_" + dstVmVtepIp.getIpv4Address().getValue(); // Add Flow Attributes flowBuilder.setId(new FlowId(flowId)); FlowKey key = new FlowKey(new FlowId(flowId)); flowBuilder.setStrict(true); flowBuilder.setBarrier(false); flowBuilder.setTableId(getTable()); flowBuilder.setKey(key); // Priority is bigger than TunnelOut_** flow flowBuilder.setPriority(32769); flowBuilder.setFlowName(flowId); flowBuilder.setHardTimeout(0); flowBuilder.setIdleTimeout(0); if (isWriteFlow) { // Instantiate the Builders for the OF Actions and Instructions InstructionBuilder ib = new InstructionBuilder(); InstructionsBuilder isb = new InstructionsBuilder(); List<Action> actionList = new ArrayList<>(); List<Instruction> instructions = Lists.newArrayList(); ActionBuilder ab = new ActionBuilder(); //load Tunnel gpe np ab.setAction(OfActionUtils.nxLoadTunGpeNpAction(Short.valueOf((short) 0x4))); ab.setOrder(actionList.size()); ab.setKey(new ActionKey(actionList.size())); actionList.add(ab.build()); // Load Dest Vm Vtep IP to Nshc1 Register int ip = InetAddresses .coerceToInteger(InetAddresses.forString(dstVmVtepIp.getIpv4Address().getValue())); long ipl = ip & 0xffffffffL; ab.setAction(OfActionUtils.nxLoadNshc1RegAction(ipl)); ab.setOrder(actionList.size()); ab.setKey(new ActionKey(actionList.size())); actionList.add(ab.build()); // Load Dest Vm VNI to Nshc1 Register ab.setAction(OfActionUtils.nxLoadNshc2RegAction(segmentationId)); ab.setOrder(actionList.size()); ab.setKey(new ActionKey(actionList.size())); actionList.add(ab.build()); // Load Dest Vm VNI to TUN_ID ab.setAction(nxLoadTunIdAction(segmentationId)); ab.setOrder(actionList.size()); ab.setKey(new ActionKey(actionList.size())); actionList.add(ab.build()); // add Output Action NodeConnectorId ncid = new NodeConnectorId("openflow:" + dpid + ":" + OFSfcTunPort); ab.setAction(OfActionUtils.outputAction(ncid)); ab.setOrder(actionList.size()); ab.setKey(new ActionKey(actionList.size())); actionList.add(ab.build()); ApplyActionsBuilder aab = new ApplyActionsBuilder(); aab.setAction(actionList); ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build()); ib.setOrder(instructions.size()); ib.setKey(new InstructionKey(instructions.size())); instructions.add(ib.build()); isb.setInstruction(instructions); flowBuilder.setInstructions(isb.build()); writeFlow(flowBuilder, nodeBuilder); } else { removeFlow(flowBuilder, nodeBuilder); } }
From source file:org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.java
public static Action nxLoadTunIPv4Action(String ipAddress, boolean groupBucket) { int ip = InetAddresses.coerceToInteger(InetAddresses.forString(ipAddress)); long ipl = ip & 0xffffffffL; return nxLoadRegAction(new DstNxTunIpv4DstCaseBuilder().setNxTunIpv4Dst(Boolean.TRUE).build(), BigInteger.valueOf(ipl), 31, groupBucket); }
From source file:org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.java
public static Action nxLoadArpSpaAction(String ipAddress) { int ip = InetAddresses.coerceToInteger(InetAddresses.forString(ipAddress)); long ipl = ip & 0xffffffffL; return nxLoadArpSpaAction(BigInteger.valueOf(ipl)); }
From source file:org.opendaylight.sfc.ofrenderer.openflow.SfcOfFlowProgrammerImpl.java
/** * Configure the NshVxgpe NSH Next Hop by matching on the NSH pathId and * index stored in the NSH header.//from w ww.j a v a2 s . co m * * @param sffNodeName * - the SFF to write the flow to * @param dstIp * - the VxLan GPE tunnel destination IP * @param nshNsp * - NSH Service Path to match on * @param nshNsi * - NSH Index to match on */ @Override public void configureNshVxgpeNextHopFlow(final String sffNodeName, final String dstIp, final String nshProxyIp, final long nshNsp, final short nshNsi) { MatchBuilder match = SfcOpenflowUtils.getNshMatches(nshNsp, nshNsi); List<Action> actionList = new ArrayList<>(); if (nshProxyIp != null) { Action actionSetNwDst = SfcOpenflowUtils.createActionNxSetTunIpv4Dst(nshProxyIp, actionList.size()); actionList.add(actionSetNwDst); if (dstIp != null) { int ip = InetAddresses.coerceToInteger(InetAddresses.forString(dstIp)); long ipl = ip & 0xffffffffL; Action actionSetNshC3 = SfcOpenflowUtils.createActionNxLoadNshc3(ipl, actionList.size()); actionList.add(actionSetNshC3); } } else if (dstIp != null) { Action actionSetNwDst = SfcOpenflowUtils.createActionNxSetTunIpv4Dst(dstIp, actionList.size()); actionList.add(actionSetNwDst); } FlowBuilder nextHopFlow = configureNextHopFlow(match, actionList); sfcOfFlowWriter.writeFlow(flowRspId, sffNodeName, nextHopFlow); }
From source file:org.opendaylight.sfc.l2renderer.openflow.SfcL2FlowProgrammerOFimpl.java
/** * This flow assures that traffic will be resubmitted from last SFF to egress table (classifier) when coexistence * is allowed. Otherwise, this flow is not necessary to create. * * @param sffNodeName - the SFF to write the flow to * @param nshNsp - the NSH Service Path to match on * @param nshNsi - the NSH Service Index to match on *///from w w w . j a va2s . com @Override public void configureVxlanGpeLastHopAppCoexistTransportEgressFlow(String sffNodeName, long nshNsp, short nshNsi, String sffIp) { // if (getTableEgress() == APP_COEXISTENCE_NOT_SET) { LOG.debug("configureVxlanGpeAppCoexistTransportEgressFlow NO AppCoexistence configured, skipping flow"); return; } int ip = InetAddresses.coerceToInteger(InetAddresses.forString(sffIp)); long ipl = ip & 0xffffffffL; MatchBuilder match = new MatchBuilder(); SfcOpenflowUtils.addMatchNshNsp(match, nshNsp); SfcOpenflowUtils.addMatchNshNsi(match, nshNsi); SfcOpenflowUtils.addMatchNshNsc1(match, ipl); int order = 0; List<Action> actionList = new ArrayList<>(); actionList.add(SfcOpenflowUtils.createActionNxMoveNsi(order++)); actionList.add(SfcOpenflowUtils.createActionNxMoveNsp(order++)); actionList.add(SfcOpenflowUtils.createActionNxMoveNsc1ToTunIpv4DstRegister(order++)); actionList.add(SfcOpenflowUtils.createActionNxMoveNsc2ToTunIdRegister(order++)); actionList.add(SfcOpenflowUtils.createActionNxSetNshc1(0L, order++)); actionList.add(SfcOpenflowUtils.createActionResubmitTable(getTableEgress(), order++)); Long vxlanOfPort = SfcOvsUtil.getVxlanOfPort(sffNodeName); MatchBuilder ofpMatch = new MatchBuilder(match.build()) .setInPort(new NodeConnectorId(vxlanOfPort.toString())); String port = OutputPortValues.INPORT.toString(); FlowBuilder transportEgressFlow = configureTransportEgressFlow(ofpMatch, actionList, port, order, FLOW_PRIORITY_TRANSPORT_EGRESS + 11); sfcL2FlowWriter.writeFlowToConfig(flowRspId, sffNodeName, transportEgressFlow); }
From source file:org.opendaylight.sfc.util.openflow.SfcOpenflowUtils.java
public static Action createActionNxSetTunIpv4Dst(String ipStr, int order) { int ip = InetAddresses.coerceToInteger(InetAddresses.forString(ipStr)); long ipl = ip & 0xffffffffL; ActionBuilder ab = createActionBuilder(order); ab.setAction(nxLoadRegAction(new DstNxTunIpv4DstCaseBuilder().setNxTunIpv4Dst(Boolean.TRUE).build(), BigInteger.valueOf(ipl), 31, false)); return ab.build(); }
From source file:org.opendaylight.sfc.ofrenderer.openflow.SfcOfFlowProgrammerImpl.java
@Override public void configureNshVxgpeAppCoexistTransportEgressFlow(final String sffNodeName, final long nshNsp, final short nshNsi, final String sffIp) { // This flow only needs to be created if App Coexistence is being used if (getTableEgress() == APP_COEXISTENCE_NOT_SET) { LOG.debug("configureNshVxgpeAppCoexistTransportEgressFlow NO AppCoexistence configured, skipping flow"); return;/*ww w.j ava 2s . c o m*/ } // Create a match checking if C1 is set to this SFF // Assuming IPv4 int ip = InetAddresses.coerceToInteger(InetAddresses.forString(sffIp)); long ipl = ip & 0xffffffffL; MatchBuilder match = SfcOpenflowUtils.getNshMatches(nshNsp, nshNsi); SfcOpenflowUtils.addMatchNshNsc1(match, ipl); // Copy/Move Nsi, Nsp, Nsc1=>TunIpv4Dst, and Nsc2=>TunId(Vnid) List<Action> actionList = new ArrayList<>(); actionList.add(SfcOpenflowUtils.createActionNxMoveNshMdtype(actionList.size())); actionList.add(SfcOpenflowUtils.createActionNxMoveNshNp(actionList.size())); actionList.add(SfcOpenflowUtils.createActionNxMoveNsi(actionList.size())); actionList.add(SfcOpenflowUtils.createActionNxMoveNsp(actionList.size())); actionList.add(SfcOpenflowUtils.createActionNxMoveNsc1ToTunIpv4DstRegister(actionList.size())); actionList.add(SfcOpenflowUtils.createActionNxMoveNsc2ToTunIdRegister(actionList.size())); /* Need to set TUN_GPE_NP for VxLAN-gpe port */ actionList.add( SfcOpenflowUtils.createActionNxLoadTunGpeNp(OpenflowConstants.TUN_GPE_NP_NSH, actionList.size())); FlowBuilder transportEgressFlow = configureTransportEgressFlow(match, actionList, EMPTY_SWITCH_PORT, FLOW_PRIORITY_TRANSPORT_EGRESS + 10, TRANSPORT_EGRESS_NSH_VXGPE_APPCOEXIST_COOKIE); sfcOfFlowWriter.writeFlow(flowRspId, sffNodeName, transportEgressFlow); }
From source file:org.opendaylight.faas.fabrics.vxlan.adapters.ovs.pipeline.PipelineL2Forwarding.java
protected InstructionBuilder createOutputGroupInstructionsToTunnelPort(NodeBuilder nodeBuilder, InstructionBuilder ib, Long dpid, Long port, Long groupId, IpAddress destTunnelIp, List<Instruction> instructions) { NodeConnectorId ncid = new NodeConnectorId(Constants.OPENFLOW_NODE_PREFIX + dpid + ":" + port); // LOG.debug("createOutputGroupInstructionsToTunnelPort() Node Connector // ID is - Type=openflow: DPID={} port={} existingInstructions={}", // dpid, port, instructions); List<Action> actionList = Lists.newArrayList(); List<Action> existingActions; if (instructions != null) { for (Instruction in : instructions) { if (in.getInstruction() instanceof ApplyActionsCase) { existingActions = ((ApplyActionsCase) in.getInstruction()).getApplyActions().getAction(); actionList.addAll(existingActions); }/*ww w .ja va 2 s. c o m*/ } } GroupBuilder groupBuilder = new GroupBuilder(); Group group = null; /* Create output action for this port */ ActionBuilder outPortActionBuilder = new ActionBuilder(); ActionBuilder loadTunIPv4ActionBuilder = new ActionBuilder(); OutputActionBuilder oab = new OutputActionBuilder(); oab.setOutputNodeConnector(ncid); outPortActionBuilder.setAction(new OutputActionCaseBuilder().setOutputAction(oab.build()).build()); /* Create load tunnel ip action */ loadTunIPv4ActionBuilder .setAction(OfActionUtils.nxLoadTunIPv4Action(destTunnelIp.getIpv4Address().getValue(), false)); boolean addNew = true; boolean groupActionAdded = false; /* Find the group action and get the group */ for (Action action : actionList) { if (action.getAction() instanceof GroupActionCase) { groupActionAdded = true; GroupActionCase groupAction = (GroupActionCase) action.getAction(); Long id = groupAction.getGroupAction().getGroupId(); String groupName = groupAction.getGroupAction().getGroup(); GroupKey key = new GroupKey(new GroupId(id)); groupBuilder.setGroupId(new GroupId(id)); groupBuilder.setGroupName(groupName); groupBuilder.setGroupType(GroupTypes.GroupAll); groupBuilder.setKey(key); group = getGroup(groupBuilder, nodeBuilder); LOG.debug("createOutputGroupInstructionsToTunnelPort: group {}", group); break; } } BucketId bucketId = null; // add tunnel port out, bucket_id=destTunnelIp.int int ip = InetAddresses.coerceToInteger(InetAddresses.forString(destTunnelIp.getIpv4Address().getValue())); long ipl = ip & 0xffffffffL; bucketId = new BucketId(ipl); if (groupActionAdded) { /* modify the action bucket in group */ groupBuilder = new GroupBuilder(group); Buckets buckets = groupBuilder.getBuckets(); for (Bucket bucket : buckets.getBucket()) { if (bucket.getBucketId().getValue() == bucketId.getValue() && bucket.getBucketId().getValue() != 1l) { LOG.warn( "Warning: createOutputGroupInstructionsToTunnelPort: the bucket is exsit for a tunnel port"); addNew = false; break; } } if (addNew) { /* the new output action is not in the bucket, add to bucket */ // Bucket bucket = buckets.getBucket().get(0); // BucketBuilder bucket = new BucketBuilder(); List<Action> bucketActionList = Lists.newArrayList(); // bucketActionList.addAll(bucket.getAction()); /* set order for new action and add to action list */ loadTunIPv4ActionBuilder.setOrder(bucketActionList.size()); loadTunIPv4ActionBuilder.setKey(new ActionKey(bucketActionList.size())); bucketActionList.add(loadTunIPv4ActionBuilder.build()); outPortActionBuilder.setOrder(bucketActionList.size()); outPortActionBuilder.setKey(new ActionKey(bucketActionList.size())); bucketActionList.add(outPortActionBuilder.build()); /* * set bucket and buckets list. Reset groupBuilder with new * buckets. */ BucketsBuilder bucketsBuilder = new BucketsBuilder(); List<Bucket> bucketList = Lists.newArrayList(); bucketList.addAll(buckets.getBucket()); BucketBuilder bucketBuilder = new BucketBuilder(); bucketBuilder.setBucketId(bucketId); bucketBuilder.setKey(new BucketKey(bucketId)); bucketBuilder.setAction(bucketActionList); bucketList.add(bucketBuilder.build()); bucketsBuilder.setBucket(bucketList); groupBuilder.setBuckets(bucketsBuilder.build()); LOG.debug("createOutputGroupInstructionsToTunnelPort: bucketList {}", bucketList); } } else { /* create group */ groupBuilder = new GroupBuilder(); groupBuilder.setGroupType(GroupTypes.GroupAll); groupBuilder.setGroupId(new GroupId(groupId)); groupBuilder.setKey(new GroupKey(new GroupId(groupId))); groupBuilder.setGroupName("Output port group " + groupId); groupBuilder.setBarrier(false); BucketsBuilder bucketBuilder = new BucketsBuilder(); List<Bucket> bucketList = Lists.newArrayList(); BucketBuilder bucket = new BucketBuilder(); bucket.setBucketId(bucketId); bucket.setKey(new BucketKey(bucketId)); /* put output action to the bucket */ List<Action> bucketActionList = Lists.newArrayList(); /* set order for new action and add to action list */ loadTunIPv4ActionBuilder.setOrder(bucketActionList.size()); loadTunIPv4ActionBuilder.setKey(new ActionKey(bucketActionList.size())); bucketActionList.add(loadTunIPv4ActionBuilder.build()); outPortActionBuilder.setOrder(bucketActionList.size()); outPortActionBuilder.setKey(new ActionKey(bucketActionList.size())); bucketActionList.add(outPortActionBuilder.build()); bucket.setAction(bucketActionList); bucketList.add(bucket.build()); bucketBuilder.setBucket(bucketList); groupBuilder.setBuckets(bucketBuilder.build()); /* Add new group action */ GroupActionBuilder groupActionB = new GroupActionBuilder(); groupActionB.setGroupId(groupId); groupActionB.setGroup("Output port group " + groupId); ActionBuilder ab = new ActionBuilder(); ab.setAction(new GroupActionCaseBuilder().setGroupAction(groupActionB.build()).build()); ab.setOrder(actionList.size()); ab.setKey(new ActionKey(actionList.size())); actionList.add(ab.build()); // groupId++; } // LOG.debug("createOutputGroupInstructions: group {}", // groupBuilder.build()); // LOG.debug("createOutputGroupInstructions: actionList {}", // actionList); if (addNew) { /* rewrite the group to group table */ writeGroup(groupBuilder, nodeBuilder); } // Create an Apply Action ApplyActionsBuilder aab = new ApplyActionsBuilder(); aab.setAction(actionList); ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build()); return ib; }
From source file:org.opendaylight.sfc.util.openflow.SfcOpenflowUtils.java
public static Action createActionNxLoadTunIpv4Dst(String ipStr, int order) { int ip = InetAddresses.coerceToInteger(InetAddresses.forString(ipStr)); long ipl = ip & 0xffffffffL; ActionBuilder ab = createActionBuilder(order); ab.setAction(nxLoadRegAction(new DstNxTunIpv4DstCaseBuilder().setNxTunIpv4Dst(Boolean.TRUE).build(), BigInteger.valueOf(ipl), 31, false)); return ab.build(); }
From source file:org.opendaylight.faas.fabrics.vxlan.adapters.ovs.pipeline.PipelineL2Forwarding.java
protected boolean removeActionFromGroup(NodeBuilder nodeBuilder, InstructionBuilder ib, Long dpid, Long port, IpAddress destTunnelIp, List<Instruction> instructions) { NodeConnectorId ncid = new NodeConnectorId(Constants.OPENFLOW_NODE_PREFIX + dpid + ":" + port); List<Action> actionList = Lists.newArrayList(); ActionBuilder ab;//from www .ja va 2s.c o m List<Action> existingActions; if (instructions != null) { for (Instruction in : instructions) { if (in.getInstruction() instanceof ApplyActionsCase) { existingActions = ((ApplyActionsCase) in.getInstruction()).getApplyActions().getAction(); actionList.addAll(existingActions); break; } } } GroupBuilder groupBuilder = new GroupBuilder(); Group group = null; boolean groupActionAdded = false; /* Find the group action and get the group */ for (Action action : actionList) { if (action.getAction() instanceof GroupActionCase) { groupActionAdded = true; GroupActionCase groupAction = (GroupActionCase) action.getAction(); Long id = groupAction.getGroupAction().getGroupId(); String groupName = groupAction.getGroupAction().getGroup(); GroupKey key = new GroupKey(new GroupId(id)); groupBuilder.setGroupId(new GroupId(id)); groupBuilder.setGroupName(groupName); groupBuilder.setGroupType(GroupTypes.GroupAll); groupBuilder.setKey(key); group = getGroup(groupBuilder, nodeBuilder); break; } } if (groupActionAdded) { /* modify the action bucket in group */ groupBuilder = new GroupBuilder(group); Buckets buckets = groupBuilder.getBuckets(); List<Action> bucketActions = Lists.newArrayList(); for (Bucket bucket : buckets.getBucket()) { // if ((destTunnelIp != null) && // (bucket.getBucketId().getValue() == 1l)) { if (bucket.getBucketId().getValue() == 1l) { // remove port from the bucket id = 1 int index = 0; boolean isPortDeleted = false; bucketActions = bucket.getAction(); for (Action action : bucketActions) { if (action.getAction() instanceof OutputActionCase) { OutputActionCase opAction = (OutputActionCase) action.getAction(); if (opAction.getOutputAction().getOutputNodeConnector().equals(ncid)) { /* * Find the output port in action list and * remove */ index = bucketActions.indexOf(action); bucketActions.remove(action); isPortDeleted = true; break; } } } if (isPortDeleted && !bucketActions.isEmpty()) { for (int i = index; i < bucketActions.size(); i++) { Action action = bucketActions.get(i); if (action.getOrder() != i) { /* Shift the action order */ ab = new ActionBuilder(); ab.setAction(action.getAction()); ab.setOrder(i); ab.setKey(new ActionKey(i)); Action actionNewOrder = ab.build(); bucketActions.remove(action); bucketActions.add(i, actionNewOrder); } } } else if (bucketActions.isEmpty()) { /* remove bucket with empty action list */ buckets.getBucket().remove(bucket); break; } } // if bucketid=1 else if (destTunnelIp != null) { // Remove the bucket to the dest Vtep int ip = InetAddresses .coerceToInteger(InetAddresses.forString(destTunnelIp.getIpv4Address().getValue())); long ipBucketId = ip & 0xffffffffL; // BucketId bucketId = new BucketId(ipl); if (bucket.getBucketId().getValue() == ipBucketId) { buckets.getBucket().remove(bucket); } } } if (!buckets.getBucket().isEmpty()) { /* rewrite the group to group table */ /* * set bucket and buckets list. Reset groupBuilder with new * buckets. */ List<Bucket> bucketList = Lists.newArrayList(); bucketList.addAll(buckets.getBucket()); BucketsBuilder bucketsBuilder = new BucketsBuilder(); bucketsBuilder.setBucket(bucketList); groupBuilder.setBuckets(bucketsBuilder.build()); LOG.debug("removeOutputPortFromGroup: bucketList {}", bucketList); writeGroup(groupBuilder, nodeBuilder); ApplyActionsBuilder aab = new ApplyActionsBuilder(); aab.setAction(actionList); ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build()); return false; } else { /* remove group with empty bucket. return true to delete flow */ removeGroup(groupBuilder, nodeBuilder); return true; } } else { /* no group for port list. flow can be removed */ return true; } }