List of usage examples for com.google.common.net InetAddresses forString
public static InetAddress forString(String ipString)
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;//from w ww. j av a2 s . co 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); }// w w w . jav a 2 s.co 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 w w w .j a va2s . 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; } }
From source file:org.dcache.ftp.door.Help.java
protected InetSocketAddress getExtendedAddressOf(String arg) throws FTPCommandException { try {//from w ww.j ava2 s. co m checkFTPCommand(!arg.isEmpty(), 501, "Syntax error: empty arguments."); ArrayList<String> splitted = Lists.newArrayList(Splitter.on(arg.charAt(0)).split(arg)); checkFTPCommand(splitted.size() == 5, 501, "Syntax error: Wrong number of arguments in '%s'.", arg); Protocol protocol = Protocol.find(splitted.get(1)); checkFTPCommand(InetAddresses.isInetAddress(splitted.get(2)), 501, "Syntax error: '%s' is no valid address.", splitted.get(2)); InetAddress address = InetAddresses.forString(splitted.get(2)); checkFTPCommand(protocol.getAddressClass().equals(address.getClass()), 501, "Protocol code does not match address: '%s'.", arg); int port = Integer.parseInt(splitted.get(3)); checkFTPCommand(port >= 1 && port <= 65536, 501, "Port number '%d' out of range [1,65536].", port); return new InetSocketAddress(address, port); } catch (NumberFormatException nfe) { throw new FTPCommandException(501, "Syntax error: no valid port number in '" + arg + "'."); } }